开发OTA备案工具-导入导出
This commit is contained in:
+1
-1
@@ -179,7 +179,7 @@ public class OtaBaCxJbxxController extends JeroController<OtaBaCxJbxx, IOtaBaCxJ
|
||||
* @return
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -65,7 +65,7 @@ public interface IOtaBaCxJbxxService extends IService<OtaBaCxJbxx> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
+51
-38
@@ -3,6 +3,7 @@ package com.jero.modules.ota.service.impl;
|
||||
import com.aliyuncs.utils.IOUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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.OtaBaCxList;
|
||||
import com.jero.modules.ota.entity.OtaBaCxTxjl;
|
||||
@@ -166,14 +167,14 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
|
||||
}
|
||||
|
||||
@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");
|
||||
OtaBaCxJbxx jbxx = parseFile(upLoadFile, cut);
|
||||
jbxx.setOtaId(otaId);
|
||||
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();
|
||||
DataFormatter formatter = new DataFormatter();
|
||||
//单元格不设置数字格式
|
||||
@@ -181,48 +182,60 @@ public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBa
|
||||
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();
|
||||
try {
|
||||
Workbook wb = ImportFileUtil.readExcel(file);
|
||||
Sheet s = wb.getSheetAt(0);
|
||||
Workbook wb = ImportFileUtil.readExcel(file);
|
||||
Sheet s = wb.getSheetAt(0);
|
||||
|
||||
Row row = s.getRow(1);
|
||||
Cell cell = row.getCell(1);
|
||||
jbxx.setQymc(getCellValue(cell, wb));
|
||||
Row row = s.getRow(1);
|
||||
Cell cell = row.getCell(1);
|
||||
jbxx.setQymc(getCellValue(cell, wb));
|
||||
|
||||
row = s.getRow(2);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setDjbh(getCellValue(cell, wb));
|
||||
row = s.getRow(3);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCplb(getCellValue(cell, wb));
|
||||
row = s.getRow(4);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setGgpc(getCellValue(cell, wb));
|
||||
row = s.getRow(5);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCpsb(getCellValue(cell, wb));
|
||||
row = s.getRow(6);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCpmc(getCellValue(cell, wb));
|
||||
row = s.getRow(7);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCpxh(getCellValue(cell, wb));
|
||||
row = s.getRow(8);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setDllx1(getCellValue(cell, wb));
|
||||
row = s.getRow(9);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setDllx2(getCellValue(cell, wb));
|
||||
row = s.getRow(10);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setTxzd(sysDictService.queryDictItemByValue("communication_terminal", getCellValue(cell, wb), cut));
|
||||
row = s.getRow(2);
|
||||
cell = row.getCell(1);
|
||||
String cpbh = getCellValue(cell, wb);
|
||||
if (StringUtils.isEmpty(cpbh)) {
|
||||
throw new JeroBootException("产品编号不能为空");
|
||||
}
|
||||
jbxx.setDjbh(cpbh);
|
||||
row = s.getRow(3);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCplb(getCellValue(cell, wb));
|
||||
row = s.getRow(4);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setGgpc(getCellValue(cell, wb));
|
||||
row = s.getRow(5);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCpsb(getCellValue(cell, wb));
|
||||
row = s.getRow(6);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCpmc(getCellValue(cell, wb));
|
||||
row = s.getRow(7);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCpxh(getCellValue(cell, wb));
|
||||
row = s.getRow(8);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setDllx1(getCellValue(cell, wb));
|
||||
row = s.getRow(9);
|
||||
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);
|
||||
cell = row.getCell(1);
|
||||
jbxx.setCdotasj(getCellValue(cell, wb));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return jbxx;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user