| package com.doumee.service.business.impl; | 
|   | 
| import com.doumee.biz.system.SystemDictDataBiz; | 
| import com.doumee.core.constants.ResponseStatus; | 
| import com.doumee.core.exception.BusinessException; | 
| import com.doumee.core.model.LoginUserInfo; | 
| import com.doumee.core.model.PageData; | 
| import com.doumee.core.model.PageWrap; | 
| import com.doumee.core.utils.Constants; | 
| import com.doumee.core.utils.Utils; | 
| import com.doumee.dao.business.YwDeviceMapper; | 
| import com.doumee.dao.business.model.Category; | 
| import com.doumee.dao.business.model.YwDevice; | 
| 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.YwDeviceService; | 
| 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 lombok.extern.java.Log; | 
| import org.apache.commons.lang3.StringUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.data.redis.core.RedisTemplate; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.util.CollectionUtils; | 
|   | 
| import java.util.Date; | 
| import java.util.List; | 
| import java.util.Objects; | 
|   | 
| /** | 
|  * 运维设备信息表Service实现 | 
|  * @author 江蹄蹄 | 
|  * @date 2024/11/19 16:07 | 
|  */ | 
| @Service | 
| public class YwDeviceServiceImpl implements YwDeviceService { | 
|   | 
|     @Autowired | 
|     private YwDeviceMapper ywDeviceMapper; | 
|   | 
|     @Autowired | 
|     private SystemDictDataBiz systemDictDataBiz; | 
|     @Autowired | 
|     private MultifileMapper multifileMapper; | 
|   | 
|     @Autowired | 
|     private RedisTemplate<String,Object> redisTemplate; | 
|   | 
|   | 
|     @Override | 
|     public Integer create(YwDevice ywDevice) { | 
|         if(Objects.isNull(ywDevice) | 
|             || StringUtils.isBlank(ywDevice.getName()) | 
|             || StringUtils.isBlank(ywDevice.getCode()) | 
|             || Objects.isNull(ywDevice.getStatus()) | 
|         ){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|         } | 
|         LoginUserInfo loginUserInfo = ywDevice.getLoginUserInfo(); | 
|         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()); | 
|         } | 
|   | 
|         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() ") | 
|                 .set(YwDevice::getEditor,user.getId()) | 
|                 .eq(YwDevice::getId,user.getId()) | 
|         ); | 
|     } | 
|   | 
|     @Override | 
|     public void delete(YwDevice ywDevice) { | 
|         UpdateWrapper<YwDevice> deleteWrapper = new UpdateWrapper<>(ywDevice); | 
|         ywDeviceMapper.delete(deleteWrapper); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) { | 
|         if (CollectionUtils.isEmpty(ids)) { | 
|             return; | 
|         } | 
|         ywDeviceMapper.deleteBatchIds(ids); | 
|     } | 
|   | 
|     @Override | 
|     public void updateById(YwDevice ywDevice) { | 
|         if(Objects.isNull(ywDevice) | 
|                 || StringUtils.isBlank(ywDevice.getName()) | 
|                 || StringUtils.isBlank(ywDevice.getCode()) | 
|                 || Objects.isNull(ywDevice.getStatus()) | 
|         ){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|         } | 
|         LoginUserInfo loginUserInfo = ywDevice.getLoginUserInfo(); | 
|         if(ywDeviceMapper.selectCount(new QueryWrapper<YwDevice>().lambda().eq(YwDevice::getIsdeleted,Constants.ZERO) | 
|                 .eq(YwDevice::getCode,ywDevice.getCode()) | 
|                 .ne(YwDevice::getId,ywDevice.getId()))>Constants.ZERO){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"设备编号重复!"); | 
|         } | 
|         ywDevice.setEditDate(new Date()); | 
|         ywDevice.setEditor(loginUserInfo.getId()); | 
|         ywDeviceMapper.updateById(ywDevice); | 
|         multifileMapper.delete(new QueryWrapper<Multifile>().lambda() | 
|                 .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()); | 
|         } | 
|   | 
|   | 
|     } | 
|   | 
|     @Override | 
|     public void updateByIdInBatch(List<YwDevice> ywDevices) { | 
|         if (CollectionUtils.isEmpty(ywDevices)) { | 
|             return; | 
|         } | 
|         for (YwDevice ywDevice: ywDevices) { | 
|             this.updateById(ywDevice); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public YwDevice findById(Integer id) { | 
|         return ywDeviceMapper.selectById(id); | 
|     } | 
|   | 
|     @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")); | 
|         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); | 
|         } | 
|         return ywDevice; | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public YwDevice findOne(YwDevice ywDevice) { | 
|         QueryWrapper<YwDevice> wrapper = new QueryWrapper<>(ywDevice); | 
|         return ywDeviceMapper.selectOne(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public List<YwDevice> findList(YwDevice ywDevice) { | 
|         QueryWrapper<YwDevice> wrapper = new QueryWrapper<>(ywDevice); | 
|         return ywDeviceMapper.selectList(wrapper); | 
|     } | 
|    | 
|     @Override | 
|     public PageData<YwDevice> findPage(PageWrap<YwDevice> pageWrap) { | 
|         IPage<YwDevice> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         MPJLambdaWrapper<YwDevice> queryWrapper = new MPJLambdaWrapper<YwDevice>(); | 
|         Utils.MP.blankToNull(pageWrap.getModel()); | 
|         YwDevice model = pageWrap.getModel(); | 
|         queryWrapper.selectAll(YwDevice.class) | 
|                 .selectAs(Category::getName,YwDevice::getCategoryName) | 
|                 .selectAs(SystemUser::getRealname,YwDevice::getRealName) | 
|                 .leftJoin(Category.class,Category::getId,YwDevice::getCateId) | 
|                 .leftJoin(SystemUser.class,SystemUser::getId,YwDevice::getUserId) | 
|                 .and(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getName()),i->i.like(YwDevice::getName,model.getName()).or().like(YwDevice::getCode,model.getName())) | 
|                 .eq(Objects.nonNull(model.getStatus()),YwDevice::getStatus,model.getStatus()) | 
|                 .eq(YwDevice::getIsdeleted,Constants.ZERO) | 
|                 .orderByDesc(YwDevice::getCreateDate) | 
|         ; | 
|         IPage iPage = ywDeviceMapper.selectJoinPage(page,YwDevice.class,queryWrapper); | 
|         return PageData.from(iPage); | 
|     } | 
|   | 
|     @Override | 
|     public long count(YwDevice ywDevice) { | 
|         QueryWrapper<YwDevice> wrapper = new QueryWrapper<>(ywDevice); | 
|         return ywDeviceMapper.selectCount(wrapper); | 
|     } | 
| } |