renkang
2025-01-03 4a2bbbc0345635ba658636fb5fef0cfcdd3447fc
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwDeviceRecordServiceImpl.java
@@ -1,21 +1,35 @@
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实现
@@ -27,10 +41,37 @@
    @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())
        ){
            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();
    }
@@ -73,6 +114,37 @@
        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)
                        .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::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.getKey()));
        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);
@@ -88,62 +160,28 @@
    @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)
                        .eq(Objects.nonNull(model.getUserId()),YwDeviceRecord::getUserId,model.getUserId())
                        .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)
                        .orderByDesc(YwDeviceRecord::getCreateDate)
        );
        return PageData.from(iPage);
    }
    @Override
@@ -151,4 +189,7 @@
        QueryWrapper<YwDeviceRecord> wrapper = new QueryWrapper<>(ywDeviceRecord);
        return ywDeviceRecordMapper.selectCount(wrapper);
    }
}