From 0178205be3ffce33af631658de35e3805641d5d3 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期一, 23 九月 2024 18:35:21 +0800
Subject: [PATCH] 代码初始化
---
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformServiceImpl.java | 185 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 179 insertions(+), 6 deletions(-)
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformServiceImpl.java
index 82709a7..893331c 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/PlatformServiceImpl.java
@@ -1,5 +1,6 @@
package com.doumee.service.business.impl;
+import cn.emay.sdk.util.StringUtil;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
@@ -7,23 +8,28 @@
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
+import com.doumee.dao.business.DeviceMapper;
+import com.doumee.dao.business.PlatformDeviceMapper;
import com.doumee.dao.business.PlatformMapper;
-import com.doumee.dao.business.model.Member;
-import com.doumee.dao.business.model.Platform;
-import com.doumee.dao.business.model.PlatformGroup;
+import com.doumee.dao.business.join.PlatformJoinMapper;
+import com.doumee.dao.business.model.*;
+import com.doumee.dao.openapi.response.PlatformNumByStatusResponse;
+import com.doumee.service.business.PlatformDeviceService;
import com.doumee.service.business.PlatformService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* 鏈堝彴淇℃伅琛⊿ervice瀹炵幇
@@ -35,10 +41,64 @@
@Autowired
private PlatformMapper platformMapper;
+ @Autowired
+ private PlatformJoinMapper platformJoinMapper;
+ @Autowired
+ private PlatformDeviceMapper platformDeviceMapper;
+ @Autowired
+ private DeviceMapper deviceMapper;
+
+
@Override
+ @Transactional(rollbackFor = {BusinessException.class,Exception.class})
public Integer create(Platform platform) {
+ platform.setCreateDate(new Date());
+ platform.setIsdeleted(Constants.ZERO);
+ platform.setCreator(platform.getLoginUserInfo().getId());
platformMapper.insert(platform);
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platform.getLedIds())){
+ List<PlatformDevice> platformDeviceList = new ArrayList<>();
+ for (Integer ledId:platform.getLedIds()) {
+ Device device = deviceMapper.selectById(ledId);
+ if(Objects.isNull(device)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鏈煡璇㈠埌led璁惧淇℃伅銆�"+ledId+"銆�");
+ }
+ PlatformDevice platformDevice = new PlatformDevice();
+ platformDevice.setIsdeleted(Constants.ZERO);
+ platformDevice.setPlatformId(platform.getId());
+ platformDevice.setCreateDate(new Date());
+ platformDevice.setCreator(platform.getLoginUserInfo().getId());
+ platformDevice.setType(Constants.ZERO);
+ platformDevice.setDeviceId(ledId.toString());
+ platformDevice.setHkId(device.getHkId());
+ platformDevice.setName(device.getName());
+ platformDeviceList.add(platformDevice);
+ }
+ platformDeviceMapper.insert(platformDeviceList);
+ }
+
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platform.getBroadcastIds())){
+ List<PlatformDevice> platformDeviceList = new ArrayList<>();
+ for (Integer broadcastId:platform.getBroadcastIds()) {
+ Device device = deviceMapper.selectById(broadcastId);
+ if(Objects.isNull(device)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鏈煡璇㈠埌骞挎挱璁惧淇℃伅銆�"+broadcastId+"銆�");
+ }
+ PlatformDevice platformDevice = new PlatformDevice();
+ platformDevice.setIsdeleted(Constants.ZERO);
+ platformDevice.setPlatformId(platform.getId());
+ platformDevice.setCreateDate(new Date());
+ platformDevice.setCreator(platform.getLoginUserInfo().getId());
+ platformDevice.setType(Constants.TWO);
+ platformDevice.setDeviceId(broadcastId.toString());
+ platformDevice.setHkId(device.getHkId());
+ platformDevice.setName(device.getName());
+ platformDeviceList.add(platformDevice);
+ }
+ platformDeviceMapper.insert(platformDeviceList);
+ }
+
return platform.getId();
}
@@ -62,9 +122,63 @@
}
@Override
+ @Transactional(rollbackFor = {BusinessException.class,Exception.class})
public void updateById(Platform platform) {
+ platform.setEditor(platform.getLoginUserInfo().getId());
+ platform.setEditDate(new Date());
+ //鍒犻櫎LED/骞挎挱鏁版嵁
+ platformDeviceMapper.delete(new QueryWrapper<PlatformDevice>().lambda()
+ .eq(PlatformDevice::getPlatformId,platform.getId())
+ .in(PlatformDevice::getType,Constants.ZERO,Constants.TWO)
+ );
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platform.getLedIds())){
+ List<PlatformDevice> platformDeviceList = new ArrayList<>();
+ String ledNames = "";
+ for (Integer ledId:platform.getLedIds()) {
+ Device device = deviceMapper.selectById(ledId);
+ if(Objects.isNull(device)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鏈煡璇㈠埌led璁惧淇℃伅銆�"+ledId+"銆�");
+ }
+ PlatformDevice platformDevice = new PlatformDevice();
+ platformDevice.setIsdeleted(Constants.ZERO);
+ platformDevice.setPlatformId(platform.getId());
+ platformDevice.setCreateDate(new Date());
+ platformDevice.setCreator(platform.getLoginUserInfo().getId());
+ platformDevice.setType(Constants.ZERO);
+ platformDevice.setDeviceId(ledId.toString());
+ platformDevice.setHkId(device.getHkId());
+ platformDevice.setName(device.getName());
+ platformDeviceList.add(platformDevice);
+ }
+ platformDeviceMapper.insert(platformDeviceList);
+ platform.setLedNames(ledNames);
+ }
+
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platform.getBroadcastIds())){
+ List<PlatformDevice> platformDeviceList = new ArrayList<>();
+ String ledNames = "";
+ for (Integer broadcastId:platform.getBroadcastIds()) {
+ Device device = deviceMapper.selectById(broadcastId);
+ if(Objects.isNull(device)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鏈煡璇㈠埌骞挎挱璁惧淇℃伅銆�"+broadcastId+"銆�");
+ }
+ PlatformDevice platformDevice = new PlatformDevice();
+ platformDevice.setIsdeleted(Constants.ZERO);
+ platformDevice.setPlatformId(platform.getId());
+ platformDevice.setCreateDate(new Date());
+ platformDevice.setCreator(platform.getLoginUserInfo().getId());
+ platformDevice.setType(Constants.TWO);
+ platformDevice.setDeviceId(broadcastId.toString());
+ platformDevice.setHkId(device.getHkId());
+ platformDevice.setName(device.getName());
+ platformDeviceList.add(platformDevice);
+ }
+ platformDeviceMapper.insert(platformDeviceList);
+ }
+
platformMapper.updateById(platform);
}
+
@Override
public void updateStatusById(Platform platform) {
Platform model =platformMapper.selectById(platform.getId());
@@ -154,7 +268,35 @@
queryWrapper.orderByAsc(sortData.getProperty());
}
}
- return PageData.from(platformMapper.selectJoinPage(page,Platform.class, queryWrapper));
+ PageData<Platform> platformPageData = PageData.from(platformMapper.selectJoinPage(page,Platform.class, queryWrapper));
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platformPageData.getRecords())){
+ for (Platform platform:platformPageData.getRecords()) {
+ List<PlatformDevice> ledDevice = platformDeviceMapper.selectList(new QueryWrapper<PlatformDevice>().lambda()
+ .eq(PlatformDevice::getPlatformId,platform.getId())
+ .eq(PlatformDevice::getType,Constants.ZERO)
+ );
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ledDevice)){
+ platform.setLedNames(String.join(",", ledDevice.stream().map(m->m.getName()).collect(Collectors.toList())));
+ platform.setLedIds(
+ ledDevice.stream().map(m->Integer.valueOf(m.getDeviceId())).collect(Collectors.toList())
+ );
+ }
+
+ List<PlatformDevice> broadcastDevice = platformDeviceMapper.selectList(new QueryWrapper<PlatformDevice>().lambda()
+ .eq(PlatformDevice::getPlatformId,platform.getId())
+ .eq(PlatformDevice::getType,Constants.TWO)
+ );
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(broadcastDevice)){
+ platform.setBroadcastNames(String.join(",", broadcastDevice.stream().map(m->m.getName()).collect(Collectors.toList())));
+ platform.setBroadcastIds(
+ broadcastDevice.stream().map(m->Integer.valueOf(m.getDeviceId())).collect(Collectors.toList())
+ );
+ }
+ }
+
+ }
+
+ return platformPageData;
}
@Override
@@ -162,4 +304,35 @@
QueryWrapper<Platform> wrapper = new QueryWrapper<>(platform);
return platformMapper.selectCount(wrapper);
}
+
+
+ @Override
+ public PlatformNumByStatusResponse getPlatformNumByStatusResponse(){
+ PlatformNumByStatusResponse platformNumByStatusResponse = new PlatformNumByStatusResponse();
+ List<Platform> platformList = platformJoinMapper.selectJoinList(Platform.class,new MPJLambdaWrapper<Platform>()
+ .selectAll(Platform.class)
+ .select(" ( select count(1) from platform_job pj where t.id = pj.PLATFORM_ID and pj.STATUS = "+Constants.PlatformJobStatus.WORKING.getKey()+" ) as workStatus ")
+ .eq(Platform::getIsdeleted,Constants.ZERO)
+ );
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platformList)){
+ //鍋滅敤鏁伴噺
+ platformNumByStatusResponse.setForbiddenNum(
+ platformList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ONE)).collect(Collectors.toList()).size()
+ );
+ //宸ヤ綔鏁伴噺
+ platformNumByStatusResponse.setUsingNum(
+ platformList.stream().filter(i->i.getWorkStatus()>Constants.ZERO).collect(Collectors.toList()).size()
+ );
+ //绌洪棽鏁伴噺
+ platformNumByStatusResponse.setIdleNum(
+ platformList.stream().filter(i->i.getWorkStatus()<=Constants.ZERO).collect(Collectors.toList()).size()
+ );
+ }
+ return platformNumByStatusResponse;
+ }
+
+
+
+
+
}
--
Gitblit v1.9.3