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实现 * @author 江蹄蹄 * @date 2024/11/19 16:07 */ @Service public class YwDeviceRecordServiceImpl implements YwDeviceRecordService { @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 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, LoginUserInfo user) { ywDeviceRecordMapper.deleteById(id); } @Override public void delete(YwDeviceRecord ywDeviceRecord) { UpdateWrapper deleteWrapper = new UpdateWrapper<>(ywDeviceRecord); ywDeviceRecordMapper.delete(deleteWrapper); } @Override public void deleteByIdInBatch(List ids, LoginUserInfo user) { if (CollectionUtils.isEmpty(ids)) { return; } ywDeviceRecordMapper.deleteBatchIds(ids); } @Override public void updateById(YwDeviceRecord ywDeviceRecord) { ywDeviceRecordMapper.updateById(ywDeviceRecord); } @Override public void updateByIdInBatch(List ywDeviceRecords) { if (CollectionUtils.isEmpty(ywDeviceRecords)) { return; } for (YwDeviceRecord ywDeviceRecord: ywDeviceRecords) { this.updateById(ywDeviceRecord); } } @Override public YwDeviceRecord findById(Integer id) { return ywDeviceRecordMapper.selectById(id); } @Override public YwDeviceRecord getDetail(Integer id) { YwDeviceRecord ywDeviceRecord = ywDeviceRecordMapper.selectJoinOne(YwDeviceRecord.class, new MPJLambdaWrapper() .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 multifiles = multifileMapper.selectList(new QueryWrapper().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 wrapper = new QueryWrapper<>(ywDeviceRecord); return ywDeviceRecordMapper.selectOne(wrapper); } @Override public List findList(YwDeviceRecord ywDeviceRecord) { QueryWrapper wrapper = new QueryWrapper<>(ywDeviceRecord); return ywDeviceRecordMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); Utils.MP.blankToNull(pageWrap.getModel()); YwDeviceRecord model = pageWrap.getModel(); IPage iPage = ywDeviceRecordMapper.selectJoinPage(page,YwDeviceRecord.class, new MPJLambdaWrapper() .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 public long count(YwDeviceRecord ywDeviceRecord) { QueryWrapper wrapper = new QueryWrapper<>(ywDeviceRecord); return ywDeviceRecordMapper.selectCount(wrapper); } }