|  |  | 
 |  |  | 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.YwDeviceRecordMapper; | 
 |  |  | import com.doumee.dao.business.model.Company; | 
 |  |  | import com.doumee.dao.business.model.YwCustomer; | 
 |  |  | import com.doumee.dao.business.model.YwDevice; | 
 |  |  | import com.doumee.dao.business.model.YwDeviceRecord; | 
 |  |  | 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.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.lang3.StringUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.util.CollectionUtils; | 
 |  |  |  | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Objects; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 运维设备运维记录表Service实现 | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private YwDeviceRecordMapper ywDeviceRecordMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private SystemDictDataBiz systemDictDataBiz; | 
 |  |  |     @Autowired | 
 |  |  |     private MultifileMapper multifileMapper; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Integer create(YwDeviceRecord ywDeviceRecord) { | 
 |  |  |         if(Objects.isNull(ywDeviceRecord) | 
 |  |  |         || Objects.isNull(ywDeviceRecord.getDeviceId()) | 
 |  |  |         || Objects.isNull(ywDeviceRecord.getStatus()) | 
 |  |  |         || StringUtils.isBlank(ywDeviceRecord.getContent()) | 
 |  |  |         ){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
 |  |  |         } | 
 |  |  |         LoginUserInfo loginUserInfo = ywDeviceRecord.getLoginUserInfo(); | 
 |  |  |         ywDeviceRecord.setCreateDate(new Date()); | 
 |  |  |         ywDeviceRecord.setCreator(loginUserInfo.getId()); | 
 |  |  |         ywDeviceRecord.setIsdeleted(Constants.ZERO); | 
 |  |  |         ywDeviceRecordMapper.insert(ywDeviceRecord); | 
 |  |  |  | 
 |  |  |         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywDeviceRecord.getMultifileList())){ | 
 |  |  |             List<Multifile> multifiles = ywDeviceRecord.getMultifileList(); | 
 |  |  |             for (Multifile multifile:multifiles) { | 
 |  |  |                 multifile.setCreator(loginUserInfo.getId()); | 
 |  |  |                 multifile.setCreateDate(new Date()); | 
 |  |  |                 multifile.setIsdeleted(Constants.ZERO); | 
 |  |  |                 multifile.setObjType(Constants.MultiFile.FN_DEVICE_RECORD_FILE.getKey()); | 
 |  |  |                 multifile.setObjId(ywDeviceRecord.getId()); | 
 |  |  |             } | 
 |  |  |             multifileMapper.insert(multifiles); | 
 |  |  |         } | 
 |  |  |         return ywDeviceRecord.getId(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void deleteById(Integer id) { | 
 |  |  |     public void deleteById(Integer id, LoginUserInfo user) { | 
 |  |  |         ywDeviceRecordMapper.deleteById(id); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void deleteByIdInBatch(List<Integer> ids) { | 
 |  |  |     public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) { | 
 |  |  |         if (CollectionUtils.isEmpty(ids)) { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  | 
 |  |  |         return ywDeviceRecordMapper.selectById(id); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public YwDeviceRecord getDetail(Integer id) { | 
 |  |  |         YwDeviceRecord ywDeviceRecord =  ywDeviceRecordMapper.selectJoinOne(YwDeviceRecord.class, | 
 |  |  |                 new MPJLambdaWrapper<YwDeviceRecord>() | 
 |  |  |                         .selectAll(YwDeviceRecord.class) | 
 |  |  |                         .selectAs(SystemUser::getRealname,YwDeviceRecord::getRealName) | 
 |  |  |                         .selectAs(SystemUser::getMobile,YwDeviceRecord::getMobile) | 
 |  |  |                         .selectAs(Company::getName,YwDeviceRecord::getCompanyName) | 
 |  |  |                         .selectAs(YwDevice::getName,YwDeviceRecord::getDeviceName) | 
 |  |  |                         .leftJoin(SystemUser.class,SystemUser::getId,YwDeviceRecord::getUserId) | 
 |  |  |                         .leftJoin(Company.class,Company::getId,SystemUser::getCompanyId) | 
 |  |  |                         .leftJoin(YwDevice.class,YwDevice::getId,YwDeviceRecord::getDeviceId) | 
 |  |  |                         .eq(YwDeviceRecord::getId,id) | 
 |  |  |                         .last(" limit  1 ") | 
 |  |  |         ); | 
 |  |  |         List<Multifile> multifiles = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda() | 
 |  |  |                 .eq(Multifile::getObjId,id).eq(Multifile::getObjType,Constants.MultiFile.FN_DEVICE_RECORD_FILE)); | 
 |  |  |         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifiles)) { | 
 |  |  |             String path = systemDictDataBiz.queryByCode(Constants.FTP, Constants.FTP_RESOURCE_PATH).getCode() | 
 |  |  |                     + systemDictDataBiz.queryByCode(Constants.FTP, Constants.YW_DEVICE).getCode(); | 
 |  |  |             for (Multifile multifile : multifiles) { | 
 |  |  |                 multifile.setFileurlFull(path + multifile.getFileurl()); | 
 |  |  |             } | 
 |  |  |             ywDeviceRecord.setMultifileList(multifiles); | 
 |  |  |         } | 
 |  |  |         return ywDeviceRecord; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public YwDeviceRecord findOne(YwDeviceRecord ywDeviceRecord) { | 
 |  |  |         QueryWrapper<YwDeviceRecord> wrapper = new QueryWrapper<>(ywDeviceRecord); | 
 |  |  | 
 |  |  |     @Override | 
 |  |  |     public PageData<YwDeviceRecord> findPage(PageWrap<YwDeviceRecord> pageWrap) { | 
 |  |  |         IPage<YwDeviceRecord> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
 |  |  |         QueryWrapper<YwDeviceRecord> queryWrapper = new QueryWrapper<>(); | 
 |  |  |         Utils.MP.blankToNull(pageWrap.getModel()); | 
 |  |  |         if (pageWrap.getModel().getId() != null) { | 
 |  |  |             queryWrapper.lambda().eq(YwDeviceRecord::getId, pageWrap.getModel().getId()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getCreator() != null) { | 
 |  |  |             queryWrapper.lambda().eq(YwDeviceRecord::getCreator, pageWrap.getModel().getCreator()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getCreateDate() != null) { | 
 |  |  |             queryWrapper.lambda().ge(YwDeviceRecord::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); | 
 |  |  |             queryWrapper.lambda().le(YwDeviceRecord::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getEditor() != null) { | 
 |  |  |             queryWrapper.lambda().eq(YwDeviceRecord::getEditor, pageWrap.getModel().getEditor()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getEditDate() != null) { | 
 |  |  |             queryWrapper.lambda().ge(YwDeviceRecord::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); | 
 |  |  |             queryWrapper.lambda().le(YwDeviceRecord::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getIsdeleted() != null) { | 
 |  |  |             queryWrapper.lambda().eq(YwDeviceRecord::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getRemark() != null) { | 
 |  |  |             queryWrapper.lambda().eq(YwDeviceRecord::getRemark, pageWrap.getModel().getRemark()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getStatus() != null) { | 
 |  |  |             queryWrapper.lambda().eq(YwDeviceRecord::getStatus, pageWrap.getModel().getStatus()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getModelNo() != null) { | 
 |  |  |             queryWrapper.lambda().eq(YwDeviceRecord::getModelNo, pageWrap.getModel().getModelNo()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getDeviceId() != null) { | 
 |  |  |             queryWrapper.lambda().eq(YwDeviceRecord::getDeviceId, pageWrap.getModel().getDeviceId()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getUserId() != null) { | 
 |  |  |             queryWrapper.lambda().eq(YwDeviceRecord::getUserId, pageWrap.getModel().getUserId()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getCompany() != null) { | 
 |  |  |             queryWrapper.lambda().ge(YwDeviceRecord::getCompany, Utils.Date.getStart(pageWrap.getModel().getCompany())); | 
 |  |  |             queryWrapper.lambda().le(YwDeviceRecord::getCompany, Utils.Date.getEnd(pageWrap.getModel().getCompany())); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getContent() != null) { | 
 |  |  |             queryWrapper.lambda().eq(YwDeviceRecord::getContent, pageWrap.getModel().getContent()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getDealDate() != null) { | 
 |  |  |             queryWrapper.lambda().ge(YwDeviceRecord::getDealDate, Utils.Date.getStart(pageWrap.getModel().getDealDate())); | 
 |  |  |             queryWrapper.lambda().le(YwDeviceRecord::getDealDate, Utils.Date.getEnd(pageWrap.getModel().getDealDate())); | 
 |  |  |         } | 
 |  |  |         for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
 |  |  |             if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
 |  |  |                 queryWrapper.orderByDesc(sortData.getProperty()); | 
 |  |  |             } else { | 
 |  |  |                 queryWrapper.orderByAsc(sortData.getProperty()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return PageData.from(ywDeviceRecordMapper.selectPage(page, queryWrapper)); | 
 |  |  |         YwDeviceRecord model = pageWrap.getModel(); | 
 |  |  |         IPage iPage = ywDeviceRecordMapper.selectJoinPage(page,YwDeviceRecord.class, | 
 |  |  |                 new MPJLambdaWrapper<YwDeviceRecord>() | 
 |  |  |                         .selectAll(YwDeviceRecord.class) | 
 |  |  |                         .selectAs(SystemUser::getRealname,YwDeviceRecord::getRealName) | 
 |  |  |                         .selectAs(SystemUser::getMobile,YwDeviceRecord::getMobile) | 
 |  |  |                         .selectAs(Company::getName,YwDeviceRecord::getCompanyName) | 
 |  |  |                         .selectAs(YwDevice::getName,YwDeviceRecord::getDeviceName) | 
 |  |  |                         .selectAs(YwDevice::getCode,YwDeviceRecord::getDeviceCode) | 
 |  |  |                         .leftJoin(SystemUser.class,SystemUser::getId,YwDeviceRecord::getUserId) | 
 |  |  |                         .leftJoin(Company.class,Company::getId,SystemUser::getCompanyId) | 
 |  |  |                         .leftJoin(YwDevice.class,YwDevice::getId,YwDeviceRecord::getDeviceId) | 
 |  |  |                         .eq(YwDeviceRecord::getIsdeleted,Constants.ZERO) | 
 |  |  |                         .and(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getDeviceName()),i->i.like(YwDevice::getName,model.getDeviceName()).or().like(YwDevice::getCode,model.getDeviceName())) | 
 |  |  |                         .ge(Objects.nonNull(model.getStartDate()),YwDeviceRecord::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getStartDate())) | 
 |  |  |                         .le(Objects.nonNull(model.getEndDate()),YwDeviceRecord::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getEndDate())) | 
 |  |  |                         .eq(YwDeviceRecord::getIsdeleted,Constants.ZERO) | 
 |  |  |         ); | 
 |  |  |         return PageData.from(iPage); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override |