npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zecaishao/kunchi-table

v0.3.114

Published

kunchi-table

Downloads

19

Readme

以下是一份示范代码,基于 Spring Boot,完成了 Excel 文件上传、解析、查询、排序、导出功能。

@RestController
@RequestMapping(\"/orders\")
public class OrderController {

@Autowired
private ProductService productService;

@PostMapping(\"/upload\")
public ResponseEntity uploadFile(@RequestParam(\"file\") MultipartFile file) throws IOException {
// 读取上传的 Excel 文件
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);

// 解析文件中的订单号
Set orderIds = new HashSet<>();
Sheet sheet = workbook.getSheetAt(0);
for (Row row : sheet) {
Cell orderIdCell = row.getCell(0);
if (orderIdCell != null && orderIdCell.getCellType() == CellType.STRING) {
orderIds.add(orderIdCell.getStringCellValue());
}
}

// 根据订单号查询商品信息,并按库存数量降序排列
List products = productService.findByOrderIds(orderIds);
Collections.sort(products, Comparator.comparing(Product::getStock).reversed());

// 导出查询结果到 Excel 文件中
Workbook resultWorkbook = new XSSFWorkbook();
Sheet resultSheet = resultWorkbook.createSheet(\"Products\");
int rowIndex = 0;
for (Product product : products) {
Row row = resultSheet.createRow(rowIndex++);
row.createCell(0).setCellValue(product.getName());
row.createCell(1).setCellValue(product.getStock());
}

// 将导出结果保存至文件中
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
resultWorkbook.write(outputStream);

LocalDate date = LocalDate.now();
String filename = String.format(\"ProductStock-%s.xlsx\", date.toString());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData(\"attachment\", filename);
return new ResponseEntity<> (outputStream.toString(), headers, HttpStatus.OK);
}

}

这段代码实现了在 /orders/upload 路径下接收一个名为 file 的文件,并完成对这个文件的解析、查询、排序、导出操作。最终导出的 Excel 文件以附件形式发送给管理员。

开发者需要根据具体业务需求,对代码中的 ProductService 做相应的调整,以保证获取商品信息的正确性。