开发OTA备案工具-导入导出

This commit is contained in:
高嵩
2023-03-27 01:17:18 +08:00
parent 0754af609c
commit a09ae32b60
3 changed files with 54 additions and 41 deletions
@@ -179,7 +179,7 @@ public class OtaBaCxJbxxController extends JeroController<OtaBaCxJbxx, IOtaBaCxJ
* @return * @return
*/ */
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
return super.importExcel(request, response, OtaBaCxJbxx.class); return super.importExcel(request, response, OtaBaCxJbxx.class);
} }
@@ -65,7 +65,7 @@ public interface IOtaBaCxJbxxService extends IService<OtaBaCxJbxx> {
OtaBaCxJbxx queryByOtaId(String otaId, String otaIdT); OtaBaCxJbxx queryByOtaId(String otaId, String otaIdT);
void exportTemplate(HttpServletResponse response, HttpServletRequest request); void exportTemplate(HttpServletResponse response, HttpServletRequest request) throws Exception;
OtaBaCxJbxx importData(MultipartFile file, String otaId, String cut); OtaBaCxJbxx importData(MultipartFile file, String otaId, String cut) throws Exception;
} }
@@ -3,6 +3,7 @@ package com.jero.modules.ota.service.impl;
import com.aliyuncs.utils.IOUtils; import com.aliyuncs.utils.IOUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.exception.JeroBootException;
import com.jero.modules.ota.entity.OtaBaCxJbxx; import com.jero.modules.ota.entity.OtaBaCxJbxx;
import com.jero.modules.ota.entity.OtaBaCxList; import com.jero.modules.ota.entity.OtaBaCxList;
import com.jero.modules.ota.entity.OtaBaCxTxjl; import com.jero.modules.ota.entity.OtaBaCxTxjl;
@@ -166,14 +167,14 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
} }
@Override @Override
public OtaBaCxJbxx importData(MultipartFile file, String otaId, String cut) { public OtaBaCxJbxx importData(MultipartFile file, String otaId, String cut) throws Exception {
File upLoadFile = ImportFileUtil.importFile(file, cut, uploadPath, "xlsx"); File upLoadFile = ImportFileUtil.importFile(file, cut, uploadPath, "xlsx");
OtaBaCxJbxx jbxx = parseFile(upLoadFile, cut); OtaBaCxJbxx jbxx = parseFile(upLoadFile, cut);
jbxx.setOtaId(otaId); jbxx.setOtaId(otaId);
return add(jbxx); return add(jbxx);
} }
public static String getCellValue(Cell cell, Workbook workbook) { public static String getCellValue(Cell cell, Workbook workbook) throws Exception {
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
DataFormatter formatter = new DataFormatter(); DataFormatter formatter = new DataFormatter();
//单元格不设置数字格式 //单元格不设置数字格式
@@ -181,48 +182,60 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
return formatter.formatCellValue(cell, evaluator); return formatter.formatCellValue(cell, evaluator);
} }
private OtaBaCxJbxx parseFile(File file, String cut) { private OtaBaCxJbxx parseFile(File file, String cut) throws Exception {
OtaBaCxJbxx jbxx = new OtaBaCxJbxx(); OtaBaCxJbxx jbxx = new OtaBaCxJbxx();
try { Workbook wb = ImportFileUtil.readExcel(file);
Workbook wb = ImportFileUtil.readExcel(file); Sheet s = wb.getSheetAt(0);
Sheet s = wb.getSheetAt(0);
Row row = s.getRow(1); Row row = s.getRow(1);
Cell cell = row.getCell(1); Cell cell = row.getCell(1);
jbxx.setQymc(getCellValue(cell, wb)); jbxx.setQymc(getCellValue(cell, wb));
row = s.getRow(2); row = s.getRow(2);
cell = row.getCell(1); cell = row.getCell(1);
jbxx.setDjbh(getCellValue(cell, wb)); String cpbh = getCellValue(cell, wb);
row = s.getRow(3); if (StringUtils.isEmpty(cpbh)) {
cell = row.getCell(1); throw new JeroBootException("产品编号不能为空");
jbxx.setCplb(getCellValue(cell, wb)); }
row = s.getRow(4); jbxx.setDjbh(cpbh);
cell = row.getCell(1); row = s.getRow(3);
jbxx.setGgpc(getCellValue(cell, wb)); cell = row.getCell(1);
row = s.getRow(5); jbxx.setCplb(getCellValue(cell, wb));
cell = row.getCell(1); row = s.getRow(4);
jbxx.setCpsb(getCellValue(cell, wb)); cell = row.getCell(1);
row = s.getRow(6); jbxx.setGgpc(getCellValue(cell, wb));
cell = row.getCell(1); row = s.getRow(5);
jbxx.setCpmc(getCellValue(cell, wb)); cell = row.getCell(1);
row = s.getRow(7); jbxx.setCpsb(getCellValue(cell, wb));
cell = row.getCell(1); row = s.getRow(6);
jbxx.setCpxh(getCellValue(cell, wb)); cell = row.getCell(1);
row = s.getRow(8); jbxx.setCpmc(getCellValue(cell, wb));
cell = row.getCell(1); row = s.getRow(7);
jbxx.setDllx1(getCellValue(cell, wb)); cell = row.getCell(1);
row = s.getRow(9); jbxx.setCpxh(getCellValue(cell, wb));
cell = row.getCell(1); row = s.getRow(8);
jbxx.setDllx2(getCellValue(cell, wb)); cell = row.getCell(1);
row = s.getRow(10); jbxx.setDllx1(getCellValue(cell, wb));
cell = row.getCell(1); row = s.getRow(9);
jbxx.setTxzd(sysDictService.queryDictItemByValue("communication_terminal", getCellValue(cell, wb), cut)); cell = row.getCell(1);
jbxx.setDllx2(getCellValue(cell, wb));
row = s.getRow(10);
cell = row.getCell(1);
String txzdStr = getCellValue(cell, wb);
if (StringUtils.isNotEmpty(txzdStr)) {
String[] txzdStrs = txzdStr.split(",");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < txzdStrs.length; i++) {
if (i >= txzdStrs.length - 1) {
sb.append(sysDictService.queryDictItemByValue("communication_terminal", txzdStrs[i], cut));
} else {
sb.append(sysDictService.queryDictItemByValue("communication_terminal", txzdStrs[i], cut)).append(",");
}
}
jbxx.setTxzd(sb.toString());
row = s.getRow(11); row = s.getRow(11);
cell = row.getCell(1); cell = row.getCell(1);
jbxx.setCdotasj(getCellValue(cell, wb)); jbxx.setCdotasj(getCellValue(cell, wb));
} catch (Exception e) {
e.printStackTrace();
} }
return jbxx; return jbxx;
} }