项目中使用的功能点

一、将产品提供的基础敏感词excel导入到数据库,关键代码及实现如下

1.添加依赖

<dependency>

            <groupId>net.sourceforge.jexcelapi</groupId>

            <artifactId>jxl</artifactId>

            <version>2.6.10</version>

        </dependency>

2.代码实现如下

try {

            File file = new File("/Users/suyanzhu/Downloads/word.xls");

            boolean exists = file.exists();

            Workbook workbook = Workbook.getWorkbook(file);

            Sheet sheet = workbook.getSheet(0);

            for (int i = 1;i < sheet.getRows();i++){

                Cell cell1 = sheet.getCell(0, i);

                Cell cell2 = sheet.getCell(1, i);


                Long typeId = 1L;

                if (cell1.getContents().equals("敏感词类型1")){

                    typeId = 1L;

                }else if (cell1.getContents().equals("敏感词类型2")){

                    typeId = 2L;

                }else if (cell1.getContents().equals("敏感词类型3")){

                    typeId = 3L;

                }else if (cell1.getContents().equals("敏感词类型4")){

                    typeId = 4L;

                }else if (cell1.getContents().equals("敏感词类型5")){

                    typeId = 5L;

                }

                SensitiveWordParamDTO build = SensitiveWordParamDTO

                        .builder().addUserId(1L)

                        .expressionState(2)

                        .name(cell2.getContents())

                        .replaceWord("*")

                        .typeId(typeId)

                        .build();

                try {

                    sensitiveWordProvider.save(build);

                } catch (SsHoursException e) {

                    e.printStackTrace();

                }

            }

            workbook.close();

        } catch (IOException e) {

            e.printStackTrace();

        } catch (BiffException e) {

            e.printStackTrace();

        }

二、一对多数据显示在一行sql

SELECT

rrc.id,

cc.nickname,

cc.mobile,

rrc.update_time,

rrc.update_user_id,

  apa.optionIds

FROM

表1 rrc

LEFT JOIN (

SELECT

GROUP_CONCAT(

rrco.option_id

) optionIds,

risk_customer_id

FROM

表2 rrco

GROUP BY

rrco.risk_customer_id

) apa ON apa.risk_customer_id = rrc.id

LEFT JOIN 表3 cc ON cc.id = rrc.customer_id

LEFT JOIN 表2 rrco ON rrc.id = rrco.risk_customer_id

WHERE

rrco.option_id = 3

GROUP BY

rrc.id

三、给定数字生成1到指定数字的数字列表

// 开始值

int start = 1;

// 结束值

int end = 100;

// 生成1,2,3,4,5...100

List<Integer> list = Stream.iterate(start, item -> item+1).limit(end).collect(Collectors.toList());



猜你喜欢

转载自blog.51cto.com/suyanzhu/2433006