# SpecServiceImpl.java

    package com.mycim.server.spec.service;

    import com.alipay.sofa.runtime.api.annotation.SofaService;
    import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
    import com.fa.sesa.threadlocal.LocalContext;
    import com.mycim.framework.utils.beans.BeanUtils;
    import com.mycim.framework.utils.lang.collections.CollectionUtils;
    import com.mycim.server.base.manager.NamedObjectManager;
    import com.mycim.server.spec.manager.*;
    import com.mycim.valueobject.ObjectList;
    import com.mycim.valueobject.prp.*;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.lang.Override;
    import java.util.ArrayList;
    import java.util.Comparator;
    import java.util.List;

    /**
     * @author Qiansheng.Wang
     * @version 1.0
     * @since 2021-4-18
     */
    @Service
    @Transactional
    @SofaService(interfaceType = SpecService.class, bindings = {@SofaServiceBinding(bindingType = "bolt")})
    public class SpecServiceImpl implements SpecService {

        @Autowired
        NamedObjectManager namedObjectManager;

        @Autowired
        SpecManager specManager;

        @Autowired
        ActivationAttributeManager activationAttributeManager;

        @Autowired
        ProcessSpecInfoManager processSpecInfoManager;

        @Autowired
        ProcessSpecItemManager processSpecItemManager;

        @Autowired
        ProductSpecInfoManager productSpecInfoManager;

        @Override
        public ProcessSpecItem getProcessSpecItemByPrimaryKey(Long processRrn, Integer processVersion, Long routeRrn,
                                                              Long operationRrn) {
            return processSpecItemManager
                    .getProcessSpecItemByPrimaryKey(processRrn, processVersion, routeRrn, operationRrn);
        }

        @Override
        public ProductSpecInfo getLatestActivatedProductSpecItemInfo(Long productRrn, Long processRrn) {
            return productSpecInfoManager.getLatestActivatedProductSpecInfo(productRrn, processRrn);
        }

        @Override
        public List<ProductSpecInfo> getAllActivatedProductSpecItemInfo(Long productRrn, Long processRrn) {
            return productSpecInfoManager.getAllActivatedProductSpecItemInfo(productRrn, processRrn);
        }

        @Override
        public ProductSpecInfo getHighestActivatedProductSpecItemInfo(Long productRrn, Long processRrn,
                                                                      Integer processVersion) {
            List<ProductSpecInfo> productSpecInfo = productSpecInfoManager
                    .getAllActivatedProductSpecItemInfo(productRrn, processRrn);
            if (CollectionUtils.isNotEmpty(productSpecInfo)) {
                return productSpecInfo.iterator().next();
            }
            return null;
        }

        @Override
        public List<ProductSpecItemDto> queryTheCompleteProcessSpecification(Long productRrn, Integer productVersion,
                                                                             String processId, Integer processVersion) {
            Long processRrn = namedObjectManager
                    .getNamedObjectRrn(processId, LocalContext.getFacilityRrn(), ObjectList.WFL_KEY);

            List<ProductSpecItem> items = activationAttributeManager
                    .getActiveProductSpec(productRrn, productVersion, processRrn, processVersion);

            List<ProductSpecItemDto> result = new ArrayList<>();
            for (ProductSpecItem productSpecItem : items) {

                ProductSpecItemDto dto = new ProductSpecItemDto();

                BeanUtils.copyProperties(productSpecItem, dto);

                result.add(dto);
            }

            result.sort(Comparator.comparing(ProductSpecItemDto::getFlowSeq));

            return result;
        }

        @Override
        public boolean hasActiveProcessSpec(long processRrn, Integer processVersionId) {
            return processSpecInfoManager.hasActiveProcessSpec(processRrn, processVersionId);
        }

        @Override
        public int getLatestActivatedProcessVersion(Long productRrn, Long processRrn) {
            return specManager.getLatestActivatedProcessVersion(productRrn, processRrn);
        }

        @Override
        public String getEqptGroupIds(Long processRrn, Integer processVersion, Long routeRrn, Long operationRrn) {
            return processSpecItemManager.getEqptGroupIds(processRrn, processVersion, routeRrn, operationRrn);
        }

        @Override
        public String getEqptGroupRrns(Long processRrn, Integer processVersion, Long routeRrn, Long operationRrn) {
            return processSpecItemManager.getEqptGroupRrns(processRrn, processVersion, routeRrn, operationRrn);
        }

        @Override
        public Boolean checkMultipath(String processId, Long processRrn, Integer processVersion, List<String> productIds) {
            return specManager.checkMultipath(processId, processRrn, processVersion, productIds);
        }

        @Override
        public Boolean checkMultiPathHasManualForContextValue(WflLinkContextValue contextValue) {
            return specManager.checkMultiPathHasManualForContextValue(contextValue);
        }

        @Override
        public String getProcessLocation(Long processRrn, Integer processVersion, Long routeRrn, Integer routeVersion,
                                         Long operationRrn) {
            return processSpecItemManager
                    .getProcessLocation(processRrn, processVersion, routeRrn, routeVersion, operationRrn);
        }

    }