|
@@ -4,6 +4,7 @@ import cn.ezhizao.common.constant.UserConstants;
|
|
|
import cn.ezhizao.common.utils.SecurityUtils;
|
|
|
import cn.ezhizao.common.utils.StringUtils;
|
|
|
import cn.ezhizao.common.utils.poi.ExcelUtil;
|
|
|
+import cn.ezhizao.framework.aspectj.lang.annotation.Excel;
|
|
|
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
|
|
|
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
|
|
|
import cn.ezhizao.framework.web.controller.BaseController;
|
|
@@ -28,6 +29,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -92,13 +95,35 @@ public class SysUserController extends BaseController
|
|
|
{
|
|
|
ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class);
|
|
|
List<SysUser> userList = util.importExcel(file.getInputStream());
|
|
|
+ String operName = getUsername();
|
|
|
+ // 获取 入Excel 表头字段
|
|
|
+ List<String> excelHeaders = util.readExcelHeaders(file.getInputStream());
|
|
|
+ //获取实体类字段
|
|
|
+ List<String> names=getExcelAnnotatedFields(SysUser.class);
|
|
|
+ //如果不存在模板中的字段,返回错误
|
|
|
+ if (!names.containsAll(excelHeaders)) {
|
|
|
+ return error("导入数据与模板不匹配!");
|
|
|
+ }
|
|
|
SysUser user = new SysUser();
|
|
|
setTenantId(user);
|
|
|
- String operName = getUsername();
|
|
|
+
|
|
|
String message = userService.importUser(userList, updateSupport, operName,user.getTenantId());
|
|
|
return success(message);
|
|
|
}
|
|
|
|
|
|
+ public List<String> getExcelAnnotatedFields(Class<?> clazz) {
|
|
|
+ Field[] fields = clazz.getDeclaredFields();
|
|
|
+ List<String> result = new ArrayList<>();
|
|
|
+ for (Field field : fields) {
|
|
|
+ if (field.isAnnotationPresent(Excel.class)) {
|
|
|
+ Excel excelAnnotation = field.getAnnotation(Excel.class);
|
|
|
+ String fieldName = excelAnnotation.name();
|
|
|
+ result.add(fieldName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/importTemplate")
|
|
|
public void importTemplate(HttpServletResponse response)
|
|
|
{
|