whyclxw
3 天以前 bfa320956f20988fe671b0c4d25aa82fe766a98d
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.whyc.controller;
 
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.pojo.MaterialCodeDictionary;
import com.whyc.service.MaterialCodeDictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
 
@RequestMapping("materialCodeDictionary")
@RestController
@Api(tags = "物料编码字典")
public class MaterialCodeDictionaryController {
 
    @Autowired
    private MaterialCodeDictionaryService service;
 
    @GetMapping("codeList")
    @ApiOperation(value = "查询编码列表分页",notes = "level:0(查询所有),1(一级编码),2(二级编码)")
    public Response<PageInfo<MaterialCodeDictionary>> getCodeList(@RequestParam int pageNum,@RequestParam int pageSize,@RequestParam int level){
        PageInfo<MaterialCodeDictionary> codeList = service.getCodeList(pageNum, pageSize, level);
        return new Response<PageInfo<MaterialCodeDictionary>>().set(1,codeList);
    }
 
    //解析导入数据,只使用一次
    @Deprecated
    @GetMapping("importData")
    public void  importData() throws IOException, InvalidFormatException {
        List<MaterialCodeDictionary> list = new LinkedList<>();
        File fileTemp = new File("C:\\Users\\29550\\Desktop\\当前项目\\202207图纸管理\\物料类别(1).xlsx");
        Workbook workbook = null;
        workbook = WorkbookFactory.create(fileTemp);
        //取第一个sheet表
        Sheet sheet = workbook.getSheetAt(0);
        int lastRowNum = sheet.getLastRowNum();
        //取第三行,并以第三行开始
        Row rowTemp = sheet.getRow(1);
        short lastCellNum = rowTemp.getLastCellNum();
        //先单独获取产品型号和版本号/分类
        Row row = sheet.getRow(1);
 
        for (int l = 1; l < lastRowNum+1; l++) {
            Cell cellTemp = sheet.getRow(l).getCell(1);
            cellTemp.setCellType(Cell.CELL_TYPE_STRING);
            if(cellTemp.getStringCellValue().equals("")){
                break;
            }
            MaterialCodeDictionary dictionary = new MaterialCodeDictionary();
 
            for (int m = 0; m < lastCellNum; m++) {
                row = sheet.getRow(l);
                Cell cell = row.getCell(m);
                String cellValue = null;
                int cellValueInt = 0;
                Double cellValueDouble = null;
                /*if(m==0 || m==2){
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cellValueDouble = cell.getNumericCellValue();
                    cellValueInt = cellValueDouble.intValue();
                }else {
                    cellValue = cell.getStringCellValue();
                }*/
 
                switch (m){
                    case 0:{dictionary.setCode((cell.getStringCellValue()));}break;
                    case 1:{dictionary.setName(cell.getStringCellValue());}break;
                    case 2:{dictionary.setParentCode((cell.getStringCellValue()));}break;
                }
            }
            list.add(dictionary);
        }
        service.insertBatch(list);
    }
 
}