吴羡
8 小时以前 e5d1fb3d5ce9468b92e79825bbcb38f05ea73aff
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodServiceImpl.java
@@ -8,6 +8,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.pojo.StandardMethodList;
import com.ruoyi.basic.event.StandardMethodSavedEvent;
import com.ruoyi.common.utils.QueryWrappers;
import com.ruoyi.basic.mapper.StandardMethodMapper;
import com.ruoyi.basic.mapper.StandardProductListMapper;
@@ -31,6 +32,7 @@
import com.ruoyi.basic.utils.StandardTreePath;
import com.ruoyi.basic.utils.StandardTreePathParser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@@ -66,6 +68,7 @@
    private LaboratoryMapper laboratoryMapper;
    private StandardTreeMapper standardTreeMapper;
    private StandardTreeTemplateBindingMapper standardTreeTemplateBindingMapper;
    private final ApplicationEventPublisher eventPublisher;
    @Value("${file.path}")
    private String filePath;
@@ -86,7 +89,8 @@
                                     StandardMethodAttachmentMapper standardMethodAttachmentMapper,
                                     LaboratoryMapper laboratoryMapper,
                                     StandardTreeMapper standardTreeMapper,
                                     StandardTreeTemplateBindingMapper standardTreeTemplateBindingMapper) {
                                     StandardTreeTemplateBindingMapper standardTreeTemplateBindingMapper,
                                     ApplicationEventPublisher eventPublisher) {
        this.standardMethodMapper = standardMethodMapper;
        this.standardProductListMapper = standardProductListMapper;
        this.standardProductListService = standardProductListService;
@@ -97,6 +101,7 @@
        this.laboratoryMapper = laboratoryMapper;
        this.standardTreeMapper = standardTreeMapper;
        this.standardTreeTemplateBindingMapper = standardTreeTemplateBindingMapper;
        this.eventPublisher = eventPublisher;
    }
    @Override
@@ -117,8 +122,12 @@
    @Transactional(rollbackFor = Exception.class)
    public Integer addStandardMethod(StandardMethod standardMethod) {
        standardMethod.setStructureTestObjectId(null);
        if (standardMethod.getNeedSearchNew() == null) {
            standardMethod.setNeedSearchNew(0);
        }
        standardMethodMapper.insert(standardMethod);
        syncIndustries(standardMethod, Collections.<Integer>emptySet());
        publishSavedEvent(standardMethod, false);
        return standardMethod.getId();
    }
@@ -149,11 +158,22 @@
        if (!oldStandardMethod.getCode().equals(standardMethod.getCode())) {
            CompletableFuture.supplyAsync(() -> replaceMethod(oldStandardMethod.getCode(), standardMethod.getCode()));
        }
        if (standardMethod.getNeedSearchNew() == null) {
            standardMethod.setNeedSearchNew(oldStandardMethod.getNeedSearchNew() == null
                    ? 0 : oldStandardMethod.getNeedSearchNew());
        }
        int i = standardMethodMapper.updateById(standardMethod);
        syncIndustries(standardMethod, new LinkedHashSet<>(selectIndustryIds(oldStandardMethod.getId())));
        publishSavedEvent(standardMethodMapper.selectById(standardMethod.getId()), true);
        return i;
    }
    private void publishSavedEvent(StandardMethod standardMethod, boolean edit) {
        eventPublisher.publishEvent(new StandardMethodSavedEvent(
                standardMethod.getId(), standardMethod.getCode(), standardMethod.getName(),
                standardMethod.getNeedSearchNew(), edit));
    }
    private List<Integer> selectIndustryIds(Integer methodId) {
        List<StandardMethodIndustry> list = standardMethodIndustryMapper.selectList(
                Wrappers.<StandardMethodIndustry>lambdaQuery()