提交 f8e8451a authored 作者: 任建宇's avatar 任建宇

11

上级 a38c85b5
......@@ -544,7 +544,7 @@ public class ImportExcelUtil {
* @throws BaseException
* 如果文件不是Excel文件、目标对象不包含解析所需的参数设置或解析过程中发生错误,抛出该异常
*/
public static <T> List<T> importExcel(InputStream excel, Class<T> targetClass, String fileName)
public static <T> List<T> importExcel(InputStream excel, Class<T> targetClass, String fileName,Map<String, String> columnMap)
throws BaseException {
if (!StringUtils.endsWithIgnoreCase(fileName, ExcelParseMode.XLS)
&& !StringUtils.endsWithIgnoreCase(fileName, ExcelParseMode.XLSX)) {
......@@ -628,10 +628,13 @@ public class ImportExcelUtil {
// 如果最大行大于实际行数或小于0(小于0表示使用实际行数),则最大行使用实际行数
// maxRow = sheet.getLastRowNum() + 1 < maxRow || maxRow < 0 ?
// sheet.getLastRowNum() + 1 : maxRow;
int q = 0;
// 遍历行
// for(int i = minRow - 1; i < maxRow; i++){
//判断所有列的数据值
StringBuffer buffer = new StringBuffer();
for (int i = 1; i < sheet.getLastRowNum() + 1; i++) {
System.out.println(sheet.getLastRowNum());
// 读取行
Row row = sheet.getRow(i);
......@@ -677,18 +680,33 @@ public class ImportExcelUtil {
for (int j = 0; j < colNum; j++) {
// 获取单元格
Cell cell = row.getCell(j);
if (cell == null) {
continue;
}
// 读取单元格数据并设置到新对象的对应属性中
// if(fieldMap.containsKey(cell.getColumnIndex())){
String key = sheet.getRow(0).getCell(cell.getColumnIndex()).toString().trim();
if (fieldMap.get(key) != null) {
System.out.println(i);
q = i;
System.out.println(++q);
System.out.println(key);
Field f = fieldMap.get(key);
System.out.println(f.getName());
System.out.println(cell.getStringCellValue());
f.setAccessible(true);
try {
//不能为空值的map
if (columnMap.get(f.getName()) != null) {
if(StringUtils.isNotBlank(cell.getStringCellValue())) {
buffer.append(++q + f.getName() + "不能为空 \n");
}
}
if (f.getType() == String.class) {
cell.setCellType(CellType.STRING);
f.set(obj, cell.getStringCellValue());
......@@ -720,7 +738,9 @@ public class ImportExcelUtil {
}*/
}
}
if (StringUtils.isNotBlank(buffer)) {
throw new BaseException(3, buffer.toString() );
}
return objectList;
}
......
......@@ -65,7 +65,7 @@ public interface TaskDao extends BaseMapper<Task> {
+ " AND task_status != 0 "
+ "</if>"
+ "<if test = 'request.taskStatus == 5'> "
+ " AND completeTime() &gt; #{request.endTime} "
+ " AND complete_Time &gt; #{request.endTime} "
+ "</if>"
+ "<if test = 'request.taskStatus == 1'> "
+ " AND task_status = #{request.taskStatus} "
......
......@@ -47,10 +47,13 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static com.constants.Constants.ARTICLE_BANNER_LIMIT;
......@@ -110,8 +113,13 @@ public class TaskServiceImpl extends ServiceImpl<TaskDao, Task> implements TaskS
@Override
public CommonResult<Object> imporTask(MultipartFile file, TaskForm taskRequest) throws BaseException, IOException {
Map<String, String> columnMap = new HashMap<String, String>();
columnMap.put("moduleName", "moduleName");
columnMap.put("taskName", "taskName");
columnMap.put("hours", "hours");
List<ExcelTaskVo> list = ImportExcelUtil.importExcel(file.getInputStream(), ExcelTaskVo.class,
file.getOriginalFilename());
file.getOriginalFilename(),columnMap);
for (ExcelTaskVo excelTaskVo : list) {
// 处理项目工时
QueryWrapper<Team> qw1 = new QueryWrapper<>();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论