yuxc
2023-12-01 89f1aace6ee8d7961069a0e482435b7d42336371
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
    }
}