add 零部件导入

This commit is contained in:
liao
2023-10-31 17:58:19 +08:00
parent cc17782df4
commit 013fd50d0d
2 changed files with 110 additions and 0 deletions
@@ -0,0 +1,69 @@
package com.jero.modules.laws.localTool.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.modules.laws.localTool.entity.Part;
import com.jero.modules.laws.localTool.entity.StandardEarlyWarning;
import com.jero.modules.system.entity.SysDictItem;
import com.jero.modules.system.service.ISysDictItemService;
import com.spire.ms.System.Collections.ArrayList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
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 java.io.File;
import java.util.List;
/**
* @Author: liao
* @Date: 2023/10/31 16:49
* @Description: 工具
*/
@Api(tags="工具")
@RestController
@RequestMapping("/laws/localTool/util")
public class LawsUtilController {
@Autowired
private ISysDictItemService sysDictItemService;
@GetMapping(value = "/import")
public void newModelImplementation() {
long start = System.currentTimeMillis();
ImportParams params = new ImportParams();
params.setHeadRows(1);
String filePath = "D:\\Download\\browser\\Chrome\\中国重汽法规智库\\零部件导入.xlsx";
List<Part> parts = ExcelImportUtil.importExcel(new File(filePath), Part.class, params);
List<SysDictItem> sysDictItems = new ArrayList();
for (int i = 0; i < parts.size(); i++) {
SysDictItem dictItem = new SysDictItem();
// 字典id
dictItem.setDictId("1696007957666533377");
// 是否标签管理显示(显示)
dictItem.setIsTagDict(1);
// 状态(启用)
dictItem.setStatus(1);
dictItem.setDelFlag(0);
// 排序
dictItem.setSortOrder(i + 1);
// 字典项值
dictItem.setItemValue(parts.get(i).getCode());
// 字典项名称
dictItem.setItemText(parts.get(i).getName());
sysDictItems.add(dictItem);
}
sysDictItemService.saveBatch(sysDictItems, sysDictItems.size());
long end = System.currentTimeMillis();
System.out.println("================导入零部件===============");
System.out.println("耗时:" + (end - start) + ",同步:" + parts.size() + "条数据");
System.out.println("=======================================");
}
}
@@ -0,0 +1,41 @@
package com.jero.modules.laws.localTool.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
/**
* @Author: liao
* @Date: 2023/10/31 16:50
* @Description: 零部件导入
*/
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="零部件导入", description="零部件导入")
public class Part {
/**分类代码*/
@Excel(name = "分类代码", width = 15)
@ApiModelProperty(value = "分类代码")
private java.lang.String code;
/**显示名称*/
@Excel(name = "显示名称", width = 15)
@ApiModelProperty(value = "显示名称")
private java.lang.String name;
/**设计规范*/
@Excel(name = "设计规范", width = 15)
@ApiModelProperty(value = "设计规范")
private java.lang.String design;
/**显示名称*/
@Excel(name = "释放规范", width = 15)
@ApiModelProperty(value = "释放规范")
private java.lang.String release;
}