考虑进程:

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

事例1:项目里边有Excel文件的解析场景,试着与ChatGPT进行了交互,现将问题收拾如下:

1.给我写一个Java版别的excel导入解析代码 (毫不客气的分配任务)

2.需求支撑100000000数据量 (事务需求改变)

3.优化代码需求支撑10000000数据量 (下降数量级,减轻难度)

4.请选用面向对象的思想给做一下封装 (初级工程师 -> 中级工程师)

5.进一步面向接口编程,抽离事务 (中级晋升应该加一点泛型诉求,代码更Beauty)

6.替换掉 poi 选用EasyExcel (替换原始的默认技术选型,替换三方包)

7.进一步优化,能支撑EasyExcel、POI自在切换 (问题没问候!原意是想让他进一步笼统,能依据SPI支撑扩展点)

8.选用操控反转方法优化 (与问题5有重复)

9.提高解析功能,选用多线程并行解析优化 (中级工程->高级工程师)

10.提高程序功率,把解析功能在提高10倍 (架构师的成原意识,这个问题的回答有点意思)

11.选用Spring IOC 操控反转方法进一步封装 (与问题8有重复)

12.增加异常 logger 打印 (优化细节)

13.增加更多的中文代码注释 (增强易读性,优化细节)

14.将中文注释替换成英文注释 (^_^ 开端走向国际化)

15.日志过错信息支撑 国际化 资源文件 (国际化的开端……)

16.把上面Excel解析的代码在给来个单元测试吧

17.…

事例2:项目里边一个ES深度分页优化的场景,问题收拾如下:

1.Elasticsearch 深度分页问题

2.Elasticsearch 深度分页Java代码

3.以上代码选用面向IOC优化

4.进一步面向对象优化

5.依据泛型进行笼统

6.将 scroll API 替换为 searchafter

7.运用 spring data elasticsearch 优化并完成 search After

8.以上代码请选用jmeter 生成一个压测脚本

9.上面Spring Data Elasticsearch 完成 search after 的示例代码请选用 groovy 语言生成测试用例

事例2的代码就不贴出来了,我们感兴趣能够自行输入以上问题进行体验!

个人体会:程序领域问问题要选用专业术语,专业术语越强越能精准给予反馈!)

阐明: 关于ChatGPT输出的代码没有做细心的Review及调试,可是看代码风格基本上是改改就能用于生产的,关于代码标准、命名仍是很认可的!

事例进程:

Happy Coding!Beauty Code!

以下是一个与ChatGPT 结对编程的一个Excel数据解析事例,我们能够依据我的考虑进程进行体验,以下放了一些截图,ChatGPT的反应速度惊人,代码版别一步步进行迭代优化,感受较深的是真实的高质量低代码平台要应运而生了!

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.read.listener.ReadListener;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet as PoiSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ExcelParser {
    private ParserType parserType;
    public ExcelParser(ParserType parserType) {
        this.parserType = parserType;
    }
    public List<Map<String, String>> parse(File file, int sheetIndex) throws IOException {
        if (parserType == ParserType.EASY_EXCEL) {
            return parseWithEasyExcel(file, sheetIndex);
        } else if (parserType == ParserType.POI) {
            return parseWithPoi(file, sheetIndex);
        } else {
            throw new IllegalArgumentException("Invalid parser type");
        }
    }
    private List<Map<String, String>> parseWithEasyExcel(File file, int sheetIndex) {
        List<Map<String, String>> data = new ArrayList<>();
        DataListener listener = new DataListener(data);
        ExcelReaderBuilder readerBuilder = EasyExcel.read(file, listener);
        Sheet sheet = new Sheet(sheetIndex + 1, 0);
        readerBuilder.sheet(sheet).doRead();
        return data;
    }
    private List<Map<String, String>> parseWithPoi(File file, int sheetIndex) throws IOException {
        List<Map<String, String>> data = new ArrayList<>();
        FileInputStream inputStream = new FileInputStream(file);
        HSSFWorkbook workbook = file.getName().endsWith(".xls") ? new HSSFWorkbook(inputStream) : new XSSFWorkbook(inputStream);
        PoiSheet sheet = workbook.getSheetAt(sheetIndex);
        List<String> headers = new ArrayList<>();
        for (Cell cell : sheet.getRow(0)) {
            headers.add(cell.getStringCellValue());
        }
        for (int i = 1; i <= sheet.getLastRowNum(); i++) {
            Row row = sheet.getRow(i);
            Map<String, String> record = new HashMap<>();
            for (int j = 0; j < headers.size(); j++) {
                Cell cell = row.getCell(j, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                String value = "";
                switch (cell.getCellType()) {
                    case STRING:
                        value = cell.getStringCellValue();
                        break;
                    case NUMERIC:
                        value = Double.toString(cell.getNumericCellValue());
                        break;
                    default:
                        value = cell.getStringCellValue();
                        break;
                }
                record.put(headers.get(j), value);
            }
            data.add(record);
        }
        workbook.close();
        inputStream.close();
        return data;
    }
    public static void main(String[] args) throws IOException {
        File file = new File("excel_file.xlsx");
        ExcelParser parser = new ExcelParser(ParserType.EASY_EXCEL);
        List<Map<String, String>> data = parser.parse(file, 0);
        System.out.println(data);
    }
}
enum ParserType {
    EASY_EXCEL,
    POI
}
class DataListener extends ReadListener<Data> {
    private List<Map<String, String>> data;
    private List<String> headers;
    public DataListener(List<Map<String, String>> data) {
        this.data = data;
        this.headers = new ArrayList<>();
    }
    @Override
    public void onException(Exception exception) {
        // 处理异常
    }
    @Override
    public void onReadError(Exception exception) {
        // 处理读取过错
    }
    @Override
    public void onSheet(int sheetIndex, Sheet sheet) {
        // 处理工作表信息
    }
    @Override
    public void onReadEnd() {
        // 读取完毕
    }
    @Override
    public void onHeadRow(Row row) {
        for (Cell cell : row) {
            headers.add(cell.getStringCellValue());
        }
    }
    @Override
    public void onRecord(Data data) {
        Map<String, String> record = new HashMap<>();
        for (int i = 0; i < headers.size(); i++) {
            record.put(headers.get(i), data.getField(i));
        }
        this.data.add(record);
    }
}
class Data {
    @ExcelProperty(index = 0)
    private String name;
    @ExcelProperty(index = 1)
    private int age;

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

import com.alibaba.excel.annotation.ExcelProperty;
import java.util.List;
import java.util.Map;
public class ExcelParser {
    private SheetParser sheetParser;
    public ExcelParser(SheetParser sheetParser) {
        this.sheetParser = sheetParser;
    }
    public List<Map<String, String>> parse(String fileName, int sheetIndex) throws Exception {
        return sheetParser.parse(fileName, sheetIndex);
    }
    public static void main(String[] args) throws Exception {
        String fileName = "excel_file.xlsx";
        SheetParser sheetParser = new EasyExcelSheetParser();
        ExcelParser parser = new ExcelParser(sheetParser);
        List<Map<String, String>> data = parser.parse(fileName, 0);
        System.out.println(data);
    }
}
interface SheetParser {
    List<Map<String, String>> parse(String fileName, int sheetIndex) throws Exception;
}
class EasyExcelSheetParser implements SheetParser {
    @Override
    public List<Map<String, String>> parse(String fileName, int sheetIndex) throws Exception {
        List<Map<String, String>> data = new ArrayList<>();
        DataListener listener = new DataListener(data);
        ExcelReaderBuilder readerBuilder = EasyExcel.read(fileName, listener);
        Sheet sheet = new Sheet(sheetIndex + 1, 0);
        readerBuilder.sheet(sheet).doRead();
        return data;
    }
}
class PoiSheetParser implements SheetParser {
    @Override
    public List<Map<String, String>> parse(String fileName, int sheetIndex) throws Exception {
        List<Map<String, String>> data = new ArrayList<>();
        FileInputStream inputStream = new FileInputStream(fileName);
        HSSFWorkbook workbook = fileName.endsWith(".xls") ? new HSSFWorkbook(inputStream) : new XSSFWorkbook(inputStream);
        PoiSheet sheet = workbook.getSheetAt(sheetIndex);
        List<String> headers = new ArrayList<>();
        for (Cell cell : sheet.getRow(0)) {
            headers.add(cell.getStringCellValue());
        }
        for (int i = 1; i <= sheet.getLastRowNum(); i++) {
            Row row = sheet.getRow(i);
            Map<String, String> record = new HashMap<>();
            for (int j = 0; j < headers.size(); j++) {
                Cell cell = row.getCell(j, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
                String value = "";
                switch (cell.getCellType()) {
                    case STRING:
                        value = cell.getStringCellValue();
                        break;
                    case NUMERIC:
                        value = Double.toString(cell.getNumericCellValue());
                        break;
                    default:
                        value = cell.getStringCellValue();
                        break;
                }
                record.put(headers.get(j), value);
            }
            data.add(record);
        }
        workbook.close();
        inputStream.close();
        return data;
    }
}
class DataListener extends ReadListener<Data> {
    private List<Map<String, String>> data;
    private List<String> headers;
    public DataListener(List<Map<String, String>> data) {
        this.data = data;
        this.headers = new ArrayList<>();
    }
    @Override
    public void onException(Exception exception) {
        // 处理异常
    }
    @Override
    public void onReadError(Exception exception) {
        // 处理读取过错
    }
    @Override
    public void onSheet(int sheetIndex, Sheet sheet) {
        // 处理工作表信息
    }
    @Override
    public void onReadEnd() {
        // 读取完毕
    }
    @Override
    public void onHeadRow(Row row) {
        for (Cell cell : row) {
            headers.add(cell.getStringCellValue());
        }
    }
    @Override
    public void onRecord(Data data) {
        Map<String, String> record = new HashMap<>();
        for (int i = 0; i < headers.size(); i++) {
            record.put(headers.get(i), data.getField(i));
        }
        this.data.add(record);
    }
}
class Data {
    @ExcelProperty(index = 0)
    private String name;
    @ExcelProperty(index = 1)
    private int age;
    // Getters and setters
}

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.read.listener.ReadListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
public class ExcelParser {
    private SheetParser sheetParser;
    public ExcelParser(SheetParser sheetParser) {
        this.sheetParser = sheetParser;
    }
    public List<Map<String, String>> parse(String fileName, int sheetIndex) throws ExecutionException, InterruptedException {
        return sheetParser.parse(fileName, sheetIndex);
    }
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        String fileName = "excel_file.xlsx";
        ExecutorService executor = Executors.newFixedThreadPool(2);
        List<Future<List<Map<String, String>>>> futures = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            SheetParser sheetParser = new EasyExcelSheetParser();
            Future<List<Map<String, String>>> future = executor.submit(() -> sheetParser.parse(fileName, i));
            futures.add(future);
        }
        List<Map<String, String>> data = new ArrayList<>();
        for (Future<List<Map<String, String>>> future : futures) {
            data.addAll(future.get());
        }
        System.out.println(data);
        executor.shutdown();
    }
}
interface SheetParser {
    List<Map<String, String>> parse(String fileName, int sheetIndex);
}
class EasyExcelSheetParser implements SheetParser {
    @Override
    public List<Map<String, String>> parse(String fileName, int sheetIndex) {
        List<Map<String, String>> data = new ArrayList<>();
        DataListener listener = new DataListener(data);
        ExcelReaderBuilder readerBuilder = EasyExcel.read(fileName, listener);
        Sheet sheet = new Sheet(sheetIndex + 1, 0);
        readerBuilder.sheet(sheet).doRead();
        return data;
    }
}
class PoiSheetParser implements SheetParser {
    @Override
    public List<Map<String, String>> parse(String fileName, int sheetIndex) throws Exception {
        // 完成 POI 的解析,类似于前面的示例
    }
}
class DataListener extends ReadListener<Data> {
    private List<Map<String, String>> data;
    private List<String> headers;
    public DataListener(List<Map<String, String>> data) {
        this.data = data;
        this.headers = new ArrayList<>();
    }
    @Override
    public void onHeadRow(Row row) {
        for (Cell cell : row) {
            headers.add(cell.getStringCellValue());
        }
    }
    @Override
    public void onRecord(Data data) {
        Map<String, String> record = new HashMap<>();
        for (int i = 0; i < headers.size(); i++) {
            record.put(headers.get(i), data.getField(i));
        }
        this.data.add(record);
    }
}
class Data {
    @ExcelProperty(index = 0)
    private String name;
    @ExcelProperty(index = 1)
    private int age;
    // Getters and setters
}

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ExcelParser {
    private SheetParser sheetParser;
    @Autowired
    public ExcelParser(SheetParser sheetParser) {
        this.sheetParser = sheetParser;
    }
    public List<Map<String, String>> parse(String fileName, int sheetIndex) throws Exception {
        return sheetParser.parse(fileName, sheetIndex);
    }
}
interface SheetParser {
    List<Map<String, String>> parse(String fileName, int sheetIndex) throws Exception;
}
@Component
class EasyExcelSheetParser implements SheetParser {
    @Override
    public List<Map<String, String>> parse(String fileName, int sheetIndex) throws Exception {
        List<Map<String, String>> data = new ArrayList<>();
        DataListener listener = new DataListener(data);
        ExcelReaderBuilder readerBuilder = EasyExcel.read(fileName, listener);
        Sheet sheet = new Sheet(sheetIndex + 1, 0);
        readerBuilder.sheet(sheet).doRead();
        return data;
    }
}
@Component
class PoiSheetParser implements SheetParser {
    @Override
    public List<Map<String, String>> parse(String fileName, int sheetIndex) throws Exception {
        // 完成 POI 的解析,类似于前面的示例
    }
}
class DataListener extends ReadListener<Data> {
    private List<Map<String, String>> data;
    private List<String> headers;
    public DataListener(List<Map<String, String>> data) {
        this.data = data;
        this.headers = new ArrayList<>();
    }
    @Override
    public void onHeadRow(Row row) {
        for (Cell cell : row) {
            headers.add(cell.getStringCellValue());
        }
    }
    @Override
    public void onRecord(Data data) {
        Map<String, String> record = new HashMap<>();
        for (int i = 0; i < headers.size(); i++) {
            record.put(headers.get(i), data.getField(i));
        }
        this.data.add(record);
    }
}
class Data {
    @ExcelProperty(index = 0)
    private String name;
    @ExcelProperty(index = 1)
    private int age;
    // Getters and setters
}

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

原理学习:

知其然,并未知其所以然!直到看到下面的解惑视频……

视频号查找: 于建国博士解说ChatGPT的工作原理及颠覆性影响,通俗易懂 (愿学有所得)

【ChatGPT应用篇】助力Beauty代码的初体验 | 京东云技术团队

职责有鸿沟、考虑无鸿沟、担任无鸿沟!!!

利用好ChatGPT一切皆有或许,用好新时代的生产力东西希望ChatGPT能助力我们更上一层楼!