Commit f1d06d47 by lzy

空间导入

parent 2373d0a7
......@@ -3,10 +3,14 @@ package com.makeit.module.controller.space;
import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.dto.platform.elder.PlatElderImportDTO;
import com.makeit.dto.platform.space.PlatSpaceAddDTO;
import com.makeit.dto.platform.space.PlatSpaceImportDTO;
import com.makeit.dto.platform.space.PlatSpaceQueryDTO;
import com.makeit.dto.platform.space.PlatSpaceVO;
import com.makeit.enums.FileSuffixEnum;
import com.makeit.service.platform.space.PlatSpaceService;
import com.makeit.utils.data.excel.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -16,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
......@@ -80,4 +85,11 @@ public class PlatSpaceController {
return ApiResponseUtils.success(data);
}
@ApiOperation(value = "导出模板")
@PostMapping("/exportTemplate")
public void exportTemplate(HttpServletResponse response) {
ExcelUtil.exportTemplate(response, "空间导入模板" + FileSuffixEnum.EXCEL.getSuffix(), PlatSpaceImportDTO.class);
}
}
package com.makeit.dto.platform.space;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Author:lzy
* @Date:2023/9/18 11:38
* @Describe:
*/
@Data
@ApiModel(value = "空间导入")
public class PlatSpaceImportDTO {
public static final String BIG_TITLE = "导入说明:\n" +
"\n" +
"1.表头带有*必填\n" +
"2.同一层级下的房间名或空间名不能重名";
@ExcelProperty({BIG_TITLE, "一级*"})
@ApiModelProperty(value = "小区/社区/街道")
private String community;
@ExcelProperty({BIG_TITLE, "二级"})
@ApiModelProperty(value = "楼栋")
private String building;
@ExcelProperty({BIG_TITLE, "三级"})
@ApiModelProperty(value = "单元")
private String unit;
@ExcelProperty({BIG_TITLE, "四级"})
@ApiModelProperty(value = "楼层")
private String floor;
@ExcelProperty({BIG_TITLE, "房间名*"})
@ApiModelProperty(value = "房间名")
private String roomName;
@ExcelProperty({BIG_TITLE, "床位数量"})
@ApiModelProperty(value = "床位数量")
private Integer bedNumber;
}
......@@ -2,11 +2,13 @@ package com.makeit.service.platform.space;
import com.baomidou.mybatisplus.extension.service.IService;
import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.vo.ExcelImportVo;
import com.makeit.dto.platform.space.PlatSpaceAddDTO;
import com.makeit.dto.platform.space.PlatSpaceQueryDTO;
import com.makeit.dto.platform.space.PlatSpaceVO;
import com.makeit.entity.platform.space.PlatSpace;
import com.makeit.vo.platform.space.PlatSpaceAndRoomVO;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
......@@ -66,4 +68,12 @@ public interface PlatSpaceService extends IService<PlatSpace> {
PlatSpaceVO child(PlatSpaceVO vo, Map<String,List<PlatSpace>> map);
PlatSpaceVO convertToVO(PlatSpace space);
/**
* 导入
* @param excelFile
* @return
*/
public ExcelImportVo importSpaceExcel(MultipartFile excelFile);
}
......@@ -4,7 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.vo.ExcelErrorVo;
import com.makeit.common.vo.ExcelImportVo;
import com.makeit.dto.platform.space.PlatSpaceAddDTO;
import com.makeit.dto.platform.space.PlatSpaceImportDTO;
import com.makeit.dto.platform.space.PlatSpaceQueryDTO;
import com.makeit.dto.platform.space.PlatSpaceVO;
import com.makeit.entity.platform.auth.PlatOrg;
......@@ -19,6 +22,7 @@ import com.makeit.service.platform.space.PlatBedService;
import com.makeit.service.platform.space.PlatRoomService;
import com.makeit.service.platform.space.PlatSpaceService;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.excel.ExcelUtil;
import com.makeit.utils.user.plat.PlatUserUtil;
import com.makeit.utils.user.plat.PlatUserVO;
import com.makeit.vo.platform.space.PlatSpaceAndRoomVO;
......@@ -26,8 +30,10 @@ import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -259,5 +265,44 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
return vo;
}
@Override
public ExcelImportVo importSpaceExcel(MultipartFile excelFile) {
ExcelImportVo excelImportVo = new ExcelImportVo();
try {
List<PlatSpaceImportDTO> list = ExcelUtil.importExcel(null,3,excelFile,PlatSpaceImportDTO.class);
List<ExcelErrorVo> errorVoList = new ArrayList<>(10);
List<String> excelField = Arrays.asList("一级*","二级","三级","四级","房间名*","床位数量");
int startRow = 3;
List<PlatSpace> listFirst = new ArrayList<>(10);
Integer errorCount = 0;
Integer successCount = 0;
for(int i=0;i<list.size();i++){
PlatSpaceImportDTO item = list.get(i);
if(StringUtil.isEmpty(item.getCommunity())){
errorVoList.add(new ExcelErrorVo(i+3,excelField.get(0),"第一层级必填"));
}
}
excelImportVo.setTotalCount(list.size());
excelImportVo.setErrorCount(errorCount);
excelImportVo.setSuccessCount(successCount);
excelImportVo.setList(errorVoList);
return excelImportVo;
}catch (Exception e){
e.printStackTrace();
}
return excelImportVo;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment