@FunctionalInterface
This commit is contained in:
@@ -8,6 +8,7 @@ package com.jeesite.common.callback;
|
||||
* 方法回调接口
|
||||
* @author ThinkGem
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface MethodCallback {
|
||||
|
||||
Object execute(Object... params);
|
||||
|
||||
@@ -409,22 +409,19 @@ public class ListUtils extends org.apache.commons.collections.ListUtils {
|
||||
final String[] ss = orderBy.trim().split(" ");
|
||||
if (ss != null){
|
||||
final String t = ss.length==2 ? ss[1] : "asc";
|
||||
Collections.sort(list, new Comparator<T>() {
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
String s1 = StringUtils.EMPTY, s2 = StringUtils.EMPTY;
|
||||
if (o1 instanceof Map){
|
||||
s1 = ObjectUtils.toString(((Map)o1).get(ss[0]));
|
||||
s2 = ObjectUtils.toString(((Map)o2).get(ss[0]));
|
||||
}else{
|
||||
s1 = ObjectUtils.toString(ReflectUtils.invokeGetter(o1, ss[0]));
|
||||
s2 = ObjectUtils.toString(ReflectUtils.invokeGetter(o2, ss[0]));
|
||||
}
|
||||
if ("asc".equalsIgnoreCase(t)){
|
||||
return s1.compareTo(s2);
|
||||
}else{
|
||||
return s2.compareTo(s1);
|
||||
}
|
||||
Collections.sort(list, (o1, o2) -> {
|
||||
String s1, s2;
|
||||
if (o1 instanceof Map){
|
||||
s1 = ObjectUtils.toString(((Map)o1).get(ss[0]));
|
||||
s2 = ObjectUtils.toString(((Map)o2).get(ss[0]));
|
||||
}else{
|
||||
s1 = ObjectUtils.toString(ReflectUtils.invokeGetter(o1, ss[0]));
|
||||
s2 = ObjectUtils.toString(ReflectUtils.invokeGetter(o2, ss[0]));
|
||||
}
|
||||
if ("asc".equalsIgnoreCase(t)){
|
||||
return s1.compareTo(s2);
|
||||
}else{
|
||||
return s2.compareTo(s1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,40 +4,6 @@
|
||||
*/
|
||||
package com.jeesite.common.utils.excel;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.CellValue;
|
||||
import org.apache.poi.ss.usermodel.DateUtil;
|
||||
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.jeesite.common.callback.MethodCallback;
|
||||
import com.jeesite.common.codec.EncodeUtils;
|
||||
import com.jeesite.common.collect.ListUtils;
|
||||
@@ -50,6 +16,23 @@ import com.jeesite.common.utils.excel.annotation.ExcelField;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelFields;
|
||||
import com.jeesite.common.utils.excel.fieldtype.FieldType;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 导入Excel文件(支持“XLS”和“XLSX”格式)
|
||||
@@ -334,23 +317,20 @@ public class ExcelImport implements Closeable {
|
||||
* @param groups 导入分组
|
||||
*/
|
||||
public <E> List<E> getDataList(Class<E> cls, final boolean isThrowException, String... groups) throws Exception{
|
||||
return getDataList(cls, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
if (isThrowException){
|
||||
Exception ex = (Exception)params[0];
|
||||
int rowNum = (int)params[1];
|
||||
int columnNum = (int)params[2];
|
||||
throw new ExcelException("Get cell value ["+rowNum+","+columnNum+"]", ex);
|
||||
}
|
||||
return null;
|
||||
return getDataList(cls, params -> {
|
||||
if (isThrowException){
|
||||
Exception ex = (Exception)params[0];
|
||||
int rowNum = (int)params[1];
|
||||
int columnNum = (int)params[2];
|
||||
throw new ExcelException("Get cell value ["+rowNum+","+columnNum+"]", ex);
|
||||
}
|
||||
return null;
|
||||
}, groups);
|
||||
}
|
||||
/**
|
||||
* 获取导入数据列表
|
||||
* @param cls 导入对象类型
|
||||
* @param isThrowException 遇见错误是否抛出异常
|
||||
* @param exceptionCallback 遇见异常时回调方法
|
||||
* @param groups 导入分组
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -4,11 +4,6 @@
|
||||
*/
|
||||
package com.jeesite.modules.cms.db;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.jeesite.common.callback.MethodCallback;
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.tests.BaseInitDataTests;
|
||||
import com.jeesite.modules.cms.dao.ArticleDao;
|
||||
@@ -20,6 +15,9 @@ import com.jeesite.modules.cms.entity.Site;
|
||||
import com.jeesite.modules.cms.service.CategoryService;
|
||||
import com.jeesite.modules.cms.service.SiteService;
|
||||
import com.jeesite.modules.gen.utils.GenUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 初始化CMS表及数据
|
||||
@@ -51,72 +49,60 @@ public class InitCmsData extends BaseInitDataTests {
|
||||
@Autowired
|
||||
private SiteService siteService;
|
||||
public void initSite() throws Exception{
|
||||
initExcelData(Site.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Site entity = (Site)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
siteService.save(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(Site.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Site entity = (Site)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
siteService.save(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
public void initCategory() throws Exception{
|
||||
initExcelData(Category.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Category entity = (Category)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
categoryService.save(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(Category.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Category entity = (Category)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
categoryService.save(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ArticleDao articleDao;
|
||||
public void initArticle() throws Exception{
|
||||
initExcelData(Article.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Article entity = (Article)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
articleDao.insert(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(Article.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Article entity = (Article)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
articleDao.insert(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ArticleDataDao articleDataDao;
|
||||
public void initArticleData() throws Exception{
|
||||
initExcelData(ArticleData.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
ArticleData entity = (ArticleData)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
articleDataDao.insert(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(ArticleData.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
ArticleData entity = (ArticleData)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
articleDataDao.insert(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,6 @@
|
||||
*/
|
||||
package com.jeesite.modules.sys.db;
|
||||
|
||||
import org.quartz.CronTrigger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.jeesite.common.callback.MethodCallback;
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.idgen.IdGen;
|
||||
import com.jeesite.common.tests.BaseInitDataTests;
|
||||
@@ -19,30 +13,12 @@ import com.jeesite.modules.job.entity.JobEntity;
|
||||
import com.jeesite.modules.msg.task.impl.MsgLocalMergePushTask;
|
||||
import com.jeesite.modules.msg.task.impl.MsgLocalPushTask;
|
||||
import com.jeesite.modules.sys.dao.RoleMenuDao;
|
||||
import com.jeesite.modules.sys.entity.Area;
|
||||
import com.jeesite.modules.sys.entity.Company;
|
||||
import com.jeesite.modules.sys.entity.Config;
|
||||
import com.jeesite.modules.sys.entity.DictData;
|
||||
import com.jeesite.modules.sys.entity.DictType;
|
||||
import com.jeesite.modules.sys.entity.EmpUser;
|
||||
import com.jeesite.modules.sys.entity.Menu;
|
||||
import com.jeesite.modules.sys.entity.Module;
|
||||
import com.jeesite.modules.sys.entity.Office;
|
||||
import com.jeesite.modules.sys.entity.Post;
|
||||
import com.jeesite.modules.sys.entity.Role;
|
||||
import com.jeesite.modules.sys.entity.RoleMenu;
|
||||
import com.jeesite.modules.sys.entity.User;
|
||||
import com.jeesite.modules.sys.service.CompanyService;
|
||||
import com.jeesite.modules.sys.service.ConfigService;
|
||||
import com.jeesite.modules.sys.service.DictDataService;
|
||||
import com.jeesite.modules.sys.service.DictTypeService;
|
||||
import com.jeesite.modules.sys.service.EmpUserService;
|
||||
import com.jeesite.modules.sys.service.MenuService;
|
||||
import com.jeesite.modules.sys.service.ModuleService;
|
||||
import com.jeesite.modules.sys.service.OfficeService;
|
||||
import com.jeesite.modules.sys.service.PostService;
|
||||
import com.jeesite.modules.sys.service.RoleService;
|
||||
import com.jeesite.modules.sys.service.UserService;
|
||||
import com.jeesite.modules.sys.entity.*;
|
||||
import com.jeesite.modules.sys.service.*;
|
||||
import org.quartz.CronTrigger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 初始化核心表数据
|
||||
@@ -112,19 +88,16 @@ public class InitCoreData extends BaseInitDataTests {
|
||||
*/
|
||||
public void initConfig() throws Exception{
|
||||
// clearTable(Config.class);
|
||||
initExcelData(Config.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Config entity = (Config)params[1];
|
||||
entity.setId(IdGen.nextId());
|
||||
entity.setIsNewRecord(true);
|
||||
configService.save(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(Config.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Config entity = (Config)params[1];
|
||||
entity.setId(IdGen.nextId());
|
||||
entity.setIsNewRecord(true);
|
||||
configService.save(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -135,18 +108,15 @@ public class InitCoreData extends BaseInitDataTests {
|
||||
*/
|
||||
public void initModule() throws Exception{
|
||||
// clearTable(Module.class);
|
||||
initExcelData(Module.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Module entity = (Module)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
moduleService.save(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(Module.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Module entity = (Module)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
moduleService.save(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -159,34 +129,28 @@ public class InitCoreData extends BaseInitDataTests {
|
||||
*/
|
||||
public void initDict() throws Exception{
|
||||
// clearTable(DictType.class);
|
||||
initExcelData(DictType.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
DictType entity = (DictType)params[1];
|
||||
entity.setId(IdGen.nextId());
|
||||
entity.setIsNewRecord(true);
|
||||
dictTypeService.save(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(DictType.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
DictType entity = (DictType)params[1];
|
||||
entity.setId(IdGen.nextId());
|
||||
entity.setIsNewRecord(true);
|
||||
dictTypeService.save(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
// clearTable(DictData.class);
|
||||
initExcelData(DictData.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
DictData entity = (DictData)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
dictDataService.save(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(DictData.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
DictData entity = (DictData)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
dictDataService.save(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -199,18 +163,15 @@ public class InitCoreData extends BaseInitDataTests {
|
||||
// clearTable(Role.class);
|
||||
// clearTable(RoleMenu.class);
|
||||
// clearTable(RoleDataScope.class);
|
||||
initExcelData(Role.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Role entity = (Role)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
roleService.save(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(Role.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Role entity = (Role)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
roleService.save(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -224,22 +185,19 @@ public class InitCoreData extends BaseInitDataTests {
|
||||
public void initMenu() throws Exception{
|
||||
// clearTable(Menu.class);
|
||||
// clearTable(RoleMenu.class);
|
||||
initExcelData(Menu.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Menu entity = (Menu)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
menuService.save(entity);
|
||||
RoleMenu rm = new RoleMenu();
|
||||
rm.setMenuCode(entity.getMenuCode());
|
||||
rm.setRoleCode(Role.CORP_ADMIN_ROLE_CODE);
|
||||
roleMenuDao.insert(rm);
|
||||
return null;
|
||||
}
|
||||
initExcelData(Menu.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Menu entity = (Menu)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
menuService.save(entity);
|
||||
RoleMenu rm = new RoleMenu();
|
||||
rm.setMenuCode(entity.getMenuCode());
|
||||
rm.setRoleCode(Role.CORP_ADMIN_ROLE_CODE);
|
||||
roleMenuDao.insert(rm);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -252,18 +210,15 @@ public class InitCoreData extends BaseInitDataTests {
|
||||
// clearTable(User.class);
|
||||
// clearTable(UserRole.class);
|
||||
// clearTable(UserDataScope.class);
|
||||
initExcelData(User.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
User entity = (User)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
userService.save(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(User.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
User entity = (User)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
userService.save(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -274,18 +229,15 @@ public class InitCoreData extends BaseInitDataTests {
|
||||
*/
|
||||
public void initOffice() throws Exception{
|
||||
// clearTable(Office.class);
|
||||
initExcelData(Office.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Office entity = (Office)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
officeService.save(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(Office.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Office entity = (Office)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
officeService.save(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -297,18 +249,15 @@ public class InitCoreData extends BaseInitDataTests {
|
||||
public void initCompany() throws Exception{
|
||||
// clearTable(Company.class);
|
||||
// clearTable(CompanyOffice.class);
|
||||
initExcelData(Company.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Company entity = (Company)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
companyService.save(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(Company.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Company entity = (Company)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
companyService.save(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -319,18 +268,15 @@ public class InitCoreData extends BaseInitDataTests {
|
||||
*/
|
||||
public void initPost() throws Exception{
|
||||
// clearTable(Post.class);
|
||||
initExcelData(Post.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Post entity = (Post)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
postService.save(entity);
|
||||
return null;
|
||||
}
|
||||
initExcelData(Post.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("save".equals(action)){
|
||||
Post entity = (Post)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
postService.save(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -342,36 +288,33 @@ public class InitCoreData extends BaseInitDataTests {
|
||||
public void initEmpUser() throws Exception{
|
||||
// clearTable(Employee.class);
|
||||
// clearTable(EmployeePost.class);
|
||||
initExcelData(EmpUser.class, new MethodCallback() {
|
||||
@Override
|
||||
public Object execute(Object... params) {
|
||||
String action = (String)params[0];
|
||||
if("check".equals(action)){
|
||||
User user = new User();
|
||||
user.setLoginCode("user1");
|
||||
return userService.getByLoginCode(user) == null;
|
||||
}else if("set".equals(action)){
|
||||
EmpUser entity = (EmpUser)params[1];
|
||||
String header = (String)params[2];
|
||||
String val = (String)params[3];
|
||||
if ("userRoleString".equals(header)){
|
||||
entity.setUserRoleString(val);
|
||||
return true;
|
||||
}else if ("employee.employeePosts".equals(header)){
|
||||
entity.getEmployee().setEmployeePosts(val);
|
||||
return true;
|
||||
}
|
||||
}else if("save".equals(action)){
|
||||
EmpUser entity = (EmpUser)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
empUserService.save(entity);
|
||||
// 设置当前为管理员,否则无法保存用户角色关系
|
||||
entity.setCurrentUser(new User(User.SUPER_ADMIN_CODE));
|
||||
userService.saveAuth(entity);
|
||||
return null;
|
||||
initExcelData(EmpUser.class, params -> {
|
||||
String action = (String)params[0];
|
||||
if("check".equals(action)){
|
||||
User user = new User();
|
||||
user.setLoginCode("user1");
|
||||
return userService.getByLoginCode(user) == null;
|
||||
}else if("set".equals(action)){
|
||||
EmpUser entity = (EmpUser)params[1];
|
||||
String header = (String)params[2];
|
||||
String val = (String)params[3];
|
||||
if ("userRoleString".equals(header)){
|
||||
entity.setUserRoleString(val);
|
||||
return true;
|
||||
}else if ("employee.employeePosts".equals(header)){
|
||||
entity.getEmployee().setEmployeePosts(val);
|
||||
return true;
|
||||
}
|
||||
}else if("save".equals(action)){
|
||||
EmpUser entity = (EmpUser)params[1];
|
||||
entity.setIsNewRecord(true);
|
||||
empUserService.save(entity);
|
||||
// 设置当前为管理员,否则无法保存用户角色关系
|
||||
entity.setCurrentUser(new User(User.SUPER_ADMIN_CODE));
|
||||
userService.saveAuth(entity);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user