xiejun
2025-01-22 d9183aa80ae17d36b79dda48c6b1d7fa22a80ee3
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeSerialAlgorithmServiceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,67 @@
package com.vci.ubcs.code.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vci.ubcs.code.annotation.MdmSerialAlgorithm;
import com.vci.ubcs.code.service.ICodeSerialAlgorithmService;
import com.vci.ubcs.code.vo.pagemodel.CodeSerialAlgorithmVO;
import com.vci.ubcs.starter.web.util.ApplicationContextProvider;
import net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
 * æµæ°´ç®—法的服务
 * @author weidy
 * @date 2022-2-17
 */
@Service
public class CodeSerialAlgorithmServiceImpl implements ICodeSerialAlgorithmService {
    /**
     * èŽ·å–æµæ°´ç®—æ³•çš„åˆ—è¡¨
     *
     * @return æµæ°´ç®—法的信息
     */
    @Override
    public IPage<CodeSerialAlgorithmVO> gridSerialAlgorithm() {
        //使用主键去扫描
        String[] beanNames = ApplicationContextProvider.getApplicationContext().getBeanNamesForAnnotation(MdmSerialAlgorithm.class);
        List<CodeSerialAlgorithmVO> voList = new ArrayList<>();
        if(beanNames!=null && beanNames.length>0){
            for(String beanName : beanNames){
                Object bean = ApplicationContextProvider.getApplicationContext().getBean(beanName);
                if(bean!=null){
                    CodeSerialAlgorithmVO algorithmVO = new CodeSerialAlgorithmVO();
               //Advised advised = (Advised)bean;
               Class<?> targetClass = AopUtils.getTargetClass(bean);
               //Class<?> targetClass = advised.getTargetSource().getTargetClass();
                    algorithmVO.setClassFullName(targetClass.getName());
               //algorithmVO.setClassFullName(beanName);
                    MdmSerialAlgorithm serialAlgorithm = targetClass.getDeclaredAnnotation(MdmSerialAlgorithm.class);
                    if(serialAlgorithm==null){
                        serialAlgorithm = targetClass.getAnnotation(MdmSerialAlgorithm.class);
                    }
                    if(serialAlgorithm !=null) {
                        algorithmVO.setName(serialAlgorithm.text());
                        algorithmVO.setDescription(serialAlgorithm.description());
                        algorithmVO.setId(serialAlgorithm.value());
                  algorithmVO.setSerialType(serialAlgorithm.serialType());
                        if(StringUtils.isBlank(algorithmVO.getId())){
                            algorithmVO.setId(beanName);
                        }
                        voList.add(algorithmVO);
                    }
                }
            }
        }
      Query query=new Query();
      IPage<CodeSerialAlgorithmVO> queryIPage =Condition.getPage(query);
      queryIPage.setRecords(voList);
      return queryIPage;
    }
}