Commit d33f257f by huangjinxin

feat:1:添加bean系统返回状态码枚举

2:添加excel导入工程师方法
1 parent fdb96df7
......@@ -125,6 +125,12 @@
<version>9.38.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
</dependencies>
<build>
......
package com.dituhui.pea.order.controller;
import com.dituhui.pea.order.service.ImportEngineerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ImportEngineerContrloller {
@Autowired
private ImportEngineerService importEngineerService;
@GetMapping("/importEngineer")
public void importEngineer(String excelUrl) {
importEngineerService.ImportEngineerByExcel(excelUrl);
}
}
package com.dituhui.pea.order.feign.bean;
import com.dituhui.pea.common.IResult;
/**
* boxi bean传输接口状态码枚举
* bean doc url https://publink-hz.feishu.cn/wiki/L4d1wwuGGiQcDqkGh3LcDJPon1i
*/
public enum BeanResultEnum implements IResult {
SUCCESS("0", "接口调用成功"),
SYSTEM_ERROR("-1", "系统错误"),
SERVICE_ERROR("2000", "业务异常"),
PARAM_ERROR("2002", "参数错误"),
TOKEN_FAILED("2005", "无效的token");
private String code;
private String message;
BeanResultEnum() {
}
BeanResultEnum(String code, String message) {
this.code = code;
this.message = message;
}
@Override
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
package com.dituhui.pea.order.service;
public interface ImportEngineerService {
void ImportEngineerByExcel(String excelurl);
}
package com.dituhui.pea.order.service.impl;
import com.dituhui.pea.order.dao.EngineerInfoDao;
import com.dituhui.pea.order.entity.EngineerInfoEntity;
import com.dituhui.pea.order.service.ImportEngineerService;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.io.FileInputStream;
@Service
public class ImportEngineerServiceImpl implements ImportEngineerService {
public static String filePath = "C:\\Users\\hjx\\Documents\\WXWork\\1688854266489901\\Cache\\File\\2023-10\\副本网点技术员清单.xlsx";
private String group_id = "gsuzhou-wangdian";
@Autowired
private EngineerInfoDao engineerInfoDao;
@Override
@Transactional
public void ImportEngineerByExcel(String excelurl) {
File file = new File(filePath);
FileInputStream fis = null;
Workbook workBook = null;
if (file.exists()) {
try {
fis = new FileInputStream(file);
workBook = WorkbookFactory.create(fis);
importEngineerByExcel(workBook, 0, 80);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void importEngineerByExcel(Workbook workBook, int sheetNo, int rowNo) {
Sheet managerSheet = workBook.getSheetAt(sheetNo);
//获取工作表名称
String managerSheetName = managerSheet.getSheetName();
System.out.println("工作表名称:" + managerSheetName);
// 获取当前Sheet的总行数
// int rowsOfManagerSheet = managerSheet.getPhysicalNumberOfRows();
System.out.println("当前表格的总行数:" + rowNo);
try {
for (int i = 1; i < rowNo; i++) {
Row row = managerSheet.getRow(i);
Cell cellCode = row.getCell(1);
Cell cellName = row.getCell(2);
Cell cellPhone = row.getCell(3);
String phone = null;
String name = null;
String code = null;
try {
//设置单元格类型
cellCode.setCellType(CellType.STRING);
cellName.setCellType(CellType.STRING);
cellPhone.setCellType(CellType.STRING);
code = cellCode.getStringCellValue();
name = cellName.getStringCellValue();
phone = cellPhone.getStringCellValue();
} catch (Exception exception) {
System.out.println(exception.getMessage());
}
if (null == phone) {
continue;
}
EngineerInfoEntity byEngineerCode = engineerInfoDao.getByEngineerCode(code);
if (null == byEngineerCode) {
byEngineerCode = new EngineerInfoEntity();
byEngineerCode.setEngineerCode(code);
byEngineerCode.setName(name);
byEngineerCode.setPhone(phone);
byEngineerCode.setGroupId(group_id);
byEngineerCode.setCosmosId(code);
byEngineerCode.setGender("男");
byEngineerCode.setBirth("");
byEngineerCode.setAddress("苏州网点");
byEngineerCode.setKind(1);
byEngineerCode.setGrade("B1");
byEngineerCode.setVehicle(1);
byEngineerCode.setMemo("无");
byEngineerCode.setBeanStatus(1);
engineerInfoDao.save(byEngineerCode);
}
System.out.println("当前表格行数:" + i);
System.out.println("当前手机号:" + phone);
System.out.println();
}
} finally {
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!