|  |  | 
 |  |  | import com.doumee.core.model.PageData; | 
 |  |  | import com.doumee.core.model.PageWrap; | 
 |  |  | import com.doumee.core.utils.Constants; | 
 |  |  | import com.doumee.core.utils.DateUtil; | 
 |  |  | import com.doumee.core.utils.Utils; | 
 |  |  | import com.doumee.dao.business.YwDeviceMapper; | 
 |  |  | import com.doumee.dao.business.YwDeviceRecordMapper; | 
 |  |  | import com.doumee.dao.business.model.Category; | 
 |  |  | import com.doumee.dao.business.model.YwDevice; | 
 |  |  | import com.doumee.dao.business.model.YwDeviceRecord; | 
 |  |  | import com.doumee.dao.business.vo.YwDeviceDataVO; | 
 |  |  | import com.doumee.dao.system.MultifileMapper; | 
 |  |  | import com.doumee.dao.system.model.Multifile; | 
 |  |  | import com.doumee.dao.system.model.SystemUser; | 
 |  |  | import com.doumee.service.business.YwDeviceRecordService; | 
 |  |  | import com.doumee.service.business.YwDeviceService; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
 |  |  | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Objects; | 
 |  |  | import java.util.stream.Collectors; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 运维设备信息表Service实现 | 
 |  |  | 
 |  |  |     private SystemDictDataBiz systemDictDataBiz; | 
 |  |  |     @Autowired | 
 |  |  |     private MultifileMapper multifileMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private YwDeviceRecordMapper ywDeviceRecordMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private RedisTemplate<String,Object> redisTemplate; | 
 |  |  | 
 |  |  |         if(ywDeviceMapper.selectCount(new QueryWrapper<YwDevice>().lambda().eq(YwDevice::getIsdeleted,Constants.ZERO).eq(YwDevice::getCode,ywDevice.getCode()))>Constants.ZERO){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"设备编号重复!"); | 
 |  |  |         } | 
 |  |  | //        if(StringUtils.isBlank(ywDevice.getCode())){ | 
 |  |  | //            String code = this.getMaxAutoMaticDeviceCode(); | 
 |  |  | //            while (ywDeviceMapper.selectCount(new QueryWrapper<YwDevice>().lambda().eq(YwDevice::getIsdeleted,Constants.ZERO).eq(YwDevice::getCode,code))>Constants.ZERO){ | 
 |  |  | //                code = this.getMaxAutoMaticDeviceCode(); | 
 |  |  | //            } | 
 |  |  | //             ywDevice.setCode(code); | 
 |  |  | //        }else{ | 
 |  |  | // | 
 |  |  | //        } | 
 |  |  |         ywDevice.setCreateDate(new Date()); | 
 |  |  |         ywDevice.setCreator(loginUserInfo.getId()); | 
 |  |  |         ywDevice.setIsdeleted(Constants.ZERO); | 
 |  |  |         ywDeviceMapper.insert(ywDevice); | 
 |  |  |  | 
 |  |  |         if(Objects.nonNull(ywDevice.getMultifile())){ | 
 |  |  |             ywDevice.getMultifile().setCreator(loginUserInfo.getId()); | 
 |  |  |             ywDevice.getMultifile().setCreateDate(new Date()); | 
 |  |  |             ywDevice.getMultifile().setIsdeleted(Constants.ZERO); | 
 |  |  |             ywDevice.getMultifile().setObjType(Constants.MultiFile.FN_DEVICE_FILE.getKey()); | 
 |  |  |             ywDevice.getMultifile().setObjId(ywDevice.getId()); | 
 |  |  |             multifileMapper.insert(ywDevice.getMultifile()); | 
 |  |  |         if(Objects.nonNull(ywDevice.getFileUrl())){ | 
 |  |  |             Multifile multifile = new Multifile(); | 
 |  |  |             multifile.setCreator(loginUserInfo.getId()); | 
 |  |  |             multifile.setCreateDate(new Date()); | 
 |  |  |             multifile.setIsdeleted(Constants.ZERO); | 
 |  |  |             multifile.setObjType(Constants.MultiFile.FN_DEVICE_FILE.getKey()); | 
 |  |  |             multifile.setObjId(ywDevice.getId()); | 
 |  |  |             multifile.setFileurl(ywDevice.getFileUrl()); | 
 |  |  |             multifileMapper.insert(multifile); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return ywDevice.getId(); | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void deleteById(Integer id, LoginUserInfo user) { | 
 |  |  |         ywDeviceMapper.update(new UpdateWrapper<YwDevice>().lambda().set(YwDevice::getIsdeleted,Constants.ONE) | 
 |  |  |                 .set(YwDevice::getEditDate," now() ") | 
 |  |  |         //查询设备是否存在运维记录 | 
 |  |  |         if(ywDeviceRecordMapper.selectCount(new QueryWrapper<YwDeviceRecord>().lambda().eq(YwDeviceRecord::getDeviceId,id).eq(YwDeviceRecord::getIsdeleted,Constants.ZERO))>Constants.ZERO){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前设备存在运维记录,无法删除"); | 
 |  |  |         }; | 
 |  |  |         ywDeviceMapper.update(new UpdateWrapper<YwDevice>() | 
 |  |  |                 .lambda().set(YwDevice::getIsdeleted,Constants.ONE) | 
 |  |  |                 .set(YwDevice::getEditDate, DateUtil.getCurrDateTime()) | 
 |  |  |                 .set(YwDevice::getEditor,user.getId()) | 
 |  |  |                 .eq(YwDevice::getId,user.getId()) | 
 |  |  |                 .eq(YwDevice::getId,id) | 
 |  |  |         ); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |                 .eq(Multifile::getObjId,ywDevice.getId()) | 
 |  |  |                 .eq(Multifile::getObjType,Constants.MultiFile.FN_DEVICE_FILE.getKey()) | 
 |  |  |         ); | 
 |  |  |         if(Objects.nonNull(ywDevice.getMultifile())){ | 
 |  |  |             ywDevice.getMultifile().setCreator(loginUserInfo.getId()); | 
 |  |  |             ywDevice.getMultifile().setCreateDate(new Date()); | 
 |  |  |             ywDevice.getMultifile().setIsdeleted(Constants.ZERO); | 
 |  |  |             ywDevice.getMultifile().setObjType(Constants.MultiFile.FN_DEVICE_FILE.getKey()); | 
 |  |  |             ywDevice.getMultifile().setObjId(ywDevice.getId()); | 
 |  |  |             multifileMapper.insert(ywDevice.getMultifile()); | 
 |  |  |         if(Objects.nonNull(ywDevice.getFileUrl())){ | 
 |  |  |             Multifile multifile = new Multifile(); | 
 |  |  |             multifile.setCreator(loginUserInfo.getId()); | 
 |  |  |             multifile.setCreateDate(new Date()); | 
 |  |  |             multifile.setIsdeleted(Constants.ZERO); | 
 |  |  |             multifile.setObjType(Constants.MultiFile.FN_DEVICE_FILE.getKey()); | 
 |  |  |             multifile.setObjId(ywDevice.getId()); | 
 |  |  |             multifile.setFileurl(ywDevice.getFileUrl()); | 
 |  |  |             multifileMapper.insert(multifile); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | 
 |  |  |     @Override | 
 |  |  |     public YwDevice getDetail(Integer id) { | 
 |  |  |         YwDevice ywDevice = ywDeviceMapper.selectById(id); | 
 |  |  |         Multifile multifile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda().eq(Multifile::getObjId,id).eq(Multifile::getObjType,Constants.MultiFile.FN_DEVICE_FILE).last(" limit 1")); | 
 |  |  |         Multifile multifile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda() | 
 |  |  |                 .eq(Multifile::getObjId,id).eq(Multifile::getObjType,Constants.MultiFile.FN_DEVICE_FILE.getKey()).last(" limit 1")); | 
 |  |  |         if(Objects.nonNull(multifile)){ | 
 |  |  |             String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() | 
 |  |  |                     +systemDictDataBiz.queryByCode(Constants.FTP,Constants.YW_DEVICE).getCode(); | 
 |  |  |             multifile.setFileurlFull(path + multifile.getFileurl()); | 
 |  |  |             ywDevice.setMultifile(multifile); | 
 |  |  |             ywDevice.setFileFullUrl(path + multifile.getFileurl()); | 
 |  |  |         } | 
 |  |  |         return ywDevice; | 
 |  |  |     } | 
 |  |  | 
 |  |  |         QueryWrapper<YwDevice> wrapper = new QueryWrapper<>(ywDevice); | 
 |  |  |         return ywDeviceMapper.selectCount(wrapper); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public YwDeviceDataVO getYwDeviceData(){ | 
 |  |  |         YwDeviceDataVO ywDeviceDataVO = new YwDeviceDataVO(); | 
 |  |  |         List<YwDevice> ywDeviceList = ywDeviceMapper.selectList(new QueryWrapper<YwDevice>().lambda().eq(YwDevice::getIsdeleted,Constants.ZERO)); | 
 |  |  |         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywDeviceList)){ | 
 |  |  |             ywDeviceDataVO.setQualityNum(ywDeviceList.size()); | 
 |  |  |             ywDeviceDataVO.setTotalNum(ywDeviceList.size()); | 
 |  |  |             ywDeviceDataVO.setNormalNum(ywDeviceList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ZERO)).collect(Collectors.toList()).size()); | 
 |  |  |             ywDeviceDataVO.setAbnormalNum(ywDeviceList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ONE)).collect(Collectors.toList()).size()); | 
 |  |  |             ywDeviceDataVO.setScrapNum(ywDeviceList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.TWO)).collect(Collectors.toList()).size()); | 
 |  |  |         } | 
 |  |  |         return ywDeviceDataVO; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  | } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  |