| | |
| | | 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; |
| | |
| | | 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.join.PlatformJoinMapper; |
| | | 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.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; |
| | | |
| | | /** |
| | |
| | | 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(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | |
| | |
| | | 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 |