Commit 18144407 authored by trumansdo's avatar trumansdo
Browse files

应用codestyle


千万千万要用vscode打开前端项目,或者关闭eslint,移除它
Signed-off-by: default avatartrumansdo <1012243881@qq.com>
parent 9b3d96a6
...@@ -19,5 +19,4 @@ public class CosonleApplication extends SpringBootServletInitializer { ...@@ -19,5 +19,4 @@ public class CosonleApplication extends SpringBootServletInitializer {
SpringApplication.run(CosonleApplication.class, args); SpringApplication.run(CosonleApplication.class, args);
} }
} }
...@@ -10,6 +10,4 @@ import com.ibeetl.admin.core.entity.CoreAudit; ...@@ -10,6 +10,4 @@ import com.ibeetl.admin.core.entity.CoreAudit;
public interface AuditConsoleDao extends BaseMapper<CoreAudit> { public interface AuditConsoleDao extends BaseMapper<CoreAudit> {
PageQuery<CoreAudit> queryByCondtion(PageQuery<CoreAudit> query); PageQuery<CoreAudit> queryByCondtion(PageQuery<CoreAudit> query);
} }
...@@ -8,11 +8,10 @@ import org.beetl.sql.core.mapper.BaseMapper; ...@@ -8,11 +8,10 @@ import org.beetl.sql.core.mapper.BaseMapper;
import com.ibeetl.admin.core.entity.CoreDict; import com.ibeetl.admin.core.entity.CoreDict;
/** /** CoreDict Dao */
* CoreDict Dao
*/
@SqlResource("console.dict") @SqlResource("console.dict")
public interface DictConsoleDao extends BaseMapper<CoreDict>{ public interface DictConsoleDao extends BaseMapper<CoreDict> {
public PageQuery<CoreDict> queryByCondition(PageQuery query); public PageQuery<CoreDict> queryByCondition(PageQuery query);
public void batchDelCoreDictByIds( List<Long> ids);
public void batchDelCoreDictByIds(List<Long> ids);
} }
...@@ -11,9 +11,8 @@ public interface MenuConsoleDao extends BaseMapper<CoreMenu> { ...@@ -11,9 +11,8 @@ public interface MenuConsoleDao extends BaseMapper<CoreMenu> {
/** /**
* 根据条件分页查询 * 根据条件分页查询
*
* @param query 查询条件 * @param query 查询条件
*/ */
void queryByCondtion(PageQuery query); void queryByCondtion(PageQuery query);
} }
...@@ -15,11 +15,10 @@ import com.ibeetl.admin.core.entity.CoreUser; ...@@ -15,11 +15,10 @@ import com.ibeetl.admin.core.entity.CoreUser;
@SqlResource("console.org") @SqlResource("console.org")
public interface OrgConsoleDao extends BaseMapper<CoreOrg> { public interface OrgConsoleDao extends BaseMapper<CoreOrg> {
void queryByCondtion(PageQuery<CoreOrg> query); void queryByCondtion(PageQuery<CoreOrg> query);
@SqlStatement(type=SqlStatementType.SELECT)
@SqlStatement(type = SqlStatementType.SELECT)
void queryUserByCondtion(PageQuery<CoreUser> query); void queryUserByCondtion(PageQuery<CoreUser> query);
void batchDelByIds(@Param(value = "ids") List<Long> ids); void batchDelByIds(@Param(value = "ids") List<Long> ids);
} }
...@@ -15,24 +15,23 @@ public interface RoleConsoleDao extends BaseMapper<CoreRole> { ...@@ -15,24 +15,23 @@ public interface RoleConsoleDao extends BaseMapper<CoreRole> {
/** /**
* 根据条件分页查询 * 根据条件分页查询
*
* @param query 查询条件 * @param query 查询条件
*/ */
void queryByCondtion(PageQuery query); void queryByCondtion(PageQuery query);
/** /**
* 批量删除角色 * 批量删除角色
*
* @param ids 角色id * @param ids 角色id
*/ */
void batchDelByIds(List<Long> ids); void batchDelByIds(List<Long> ids);
void batchDeleteRoleFunction(List<Long> ids); void batchDeleteRoleFunction(List<Long> ids);
void batchDeleteRoleMenu(List<Long> ids); void batchDeleteRoleMenu(List<Long> ids);
void batchDeleteUserRole(List<Long> ids);
void batchDeleteUserRole(List<Long> ids);
PageQuery<CoreUser> queryUser(PageQuery query); PageQuery<CoreUser> queryUser(PageQuery query);
} }
...@@ -12,12 +12,9 @@ import com.ibeetl.admin.core.entity.CoreRoleFunction; ...@@ -12,12 +12,9 @@ import com.ibeetl.admin.core.entity.CoreRoleFunction;
@SqlResource("console.roleFunction") @SqlResource("console.roleFunction")
public interface RoleFunctionConsoleDao extends BaseMapper<CoreRoleFunction> { public interface RoleFunctionConsoleDao extends BaseMapper<CoreRoleFunction> {
void deleteRoleFunction(List<Long> ids); void deleteRoleFunction(List<Long> ids);
List<Long> getFunctionIdByRole(Long roleId); List<Long> getFunctionIdByRole(Long roleId);
List<RoleDataAccessFunction> getQueryFunctionAndRoleData(Long roleId); List<RoleDataAccessFunction> getQueryFunctionAndRoleData(Long roleId);
} }
...@@ -16,11 +16,9 @@ public interface UserConsoleDao extends BaseMapper<CoreUser> { ...@@ -16,11 +16,9 @@ public interface UserConsoleDao extends BaseMapper<CoreUser> {
PageQuery<CoreUser> queryByCondtion(PageQuery<CoreUser> query); PageQuery<CoreUser> queryByCondtion(PageQuery<CoreUser> query);
void batchDelUserByIds( List<Long> ids); void batchDelUserByIds(List<Long> ids);
void batchUpdateUserState(List<Long> ids, GeneralStateEnum state); void batchUpdateUserState(List<Long> ids, GeneralStateEnum state);
List<CoreUserRole> queryUserRole( Long id,Long orgId,Long roleId); List<CoreUserRole> queryUserRole(Long id, Long orgId, Long roleId);
} }
...@@ -13,8 +13,7 @@ import com.ibeetl.admin.core.service.CoreBaseService; ...@@ -13,8 +13,7 @@ import com.ibeetl.admin.core.service.CoreBaseService;
@Transactional @Transactional
public class AuditConsoleService extends CoreBaseService<CoreAudit> { public class AuditConsoleService extends CoreBaseService<CoreAudit> {
@Autowired @Autowired AuditConsoleDao auditConsoleDao;
AuditConsoleDao auditConsoleDao;
/** /**
* 根据条件查询 * 根据条件查询
...@@ -25,7 +24,4 @@ public class AuditConsoleService extends CoreBaseService<CoreAudit> { ...@@ -25,7 +24,4 @@ public class AuditConsoleService extends CoreBaseService<CoreAudit> {
PageQuery<CoreAudit> ret = auditConsoleDao.queryByCondtion(query); PageQuery<CoreAudit> ret = auditConsoleDao.queryByCondtion(query);
queryListAfter(ret.getList()); queryListAfter(ret.getList());
} }
} }
...@@ -19,48 +19,46 @@ import com.ibeetl.admin.core.service.CoreBaseService; ...@@ -19,48 +19,46 @@ import com.ibeetl.admin.core.service.CoreBaseService;
import com.ibeetl.admin.core.util.ExcelError; import com.ibeetl.admin.core.util.ExcelError;
import com.ibeetl.admin.core.util.PlatformException; import com.ibeetl.admin.core.util.PlatformException;
/** /** CoreDict Service */
* CoreDict Service
*/
@Service @Service
@Transactional @Transactional
public class DictConsoleService extends CoreBaseService<CoreDict> { public class DictConsoleService extends CoreBaseService<CoreDict> {
@Autowired private DictConsoleDao dictDao; @Autowired private DictConsoleDao dictDao;
public PageQuery<CoreDict>queryByCondition(PageQuery query){ public PageQuery<CoreDict> queryByCondition(PageQuery query) {
PageQuery ret = dictDao.queryByCondition(query); PageQuery ret = dictDao.queryByCondition(query);
queryListAfter(ret.getList()); queryListAfter(ret.getList());
return ret; return ret;
} }
public void batchDelCoreDict(List<Long> ids){ public void batchDelCoreDict(List<Long> ids) {
try { try {
//TODO,找到数据字典所有子类,设置删除标记 // TODO,找到数据字典所有子类,设置删除标记
dictDao.batchDelCoreDictByIds(ids); dictDao.batchDelCoreDictByIds(ids);
} catch (Exception e) { } catch (Exception e) {
throw new PlatformException("批量删除CoreDict失败", e); throw new PlatformException("批量删除CoreDict失败", e);
} }
} }
public List<CoreDict> queryExcel(PageQuery<CoreUser> query) { public List<CoreDict> queryExcel(PageQuery<CoreUser> query) {
//同查询,不需要额外数据 // 同查询,不需要额外数据
PageQuery ret = dictDao.queryByCondition(query); PageQuery ret = dictDao.queryByCondition(query);
queryListAfter(ret.getList()); queryListAfter(ret.getList());
return ret.getList(); return ret.getList();
} }
/** /**
* 参考:dict_mapping.xml * 参考:dict_mapping.xml
*
* @param list * @param list
* @return * @return
*/ */
public void batchInsert(List<DictExcelImportData> list) { public void batchInsert(List<DictExcelImportData> list) {
int dataStartRow = 2; int dataStartRow = 2;
final Map<Integer,DictExcelImportData> map = new HashMap<>(); final Map<Integer, DictExcelImportData> map = new HashMap<>();
list.forEach((item)->map.put(item.getExcelId(), item)); list.forEach((item) -> map.put(item.getExcelId(), item));
//逐个按照顺序导入 // 逐个按照顺序导入
for(DictExcelImportData item:list) { for (DictExcelImportData item : list) {
CoreDict dict = new CoreDict(); CoreDict dict = new CoreDict();
dict.setName(item.getName()); dict.setName(item.getName());
dict.setRemark(item.getRemark()); dict.setRemark(item.getRemark());
...@@ -68,46 +66,42 @@ public class DictConsoleService extends CoreBaseService<CoreDict> { ...@@ -68,46 +66,42 @@ public class DictConsoleService extends CoreBaseService<CoreDict> {
dict.setTypeName(item.getTypeName()); dict.setTypeName(item.getTypeName());
dict.setValue(item.getValue()); dict.setValue(item.getValue());
//设置父字典 // 设置父字典
if(item.getParentExcelId()!=0) { if (item.getParentExcelId() != 0) {
DictExcelImportData parentItem = map.get(item.getParentExcelId()); DictExcelImportData parentItem = map.get(item.getParentExcelId());
if(parentItem==null) { if (parentItem == null) {
//硬编码,TODO,用reader缺少校验,替换手写导入 // 硬编码,TODO,用reader缺少校验,替换手写导入
int row = item.getExcelId()+dataStartRow; int row = item.getExcelId() + dataStartRow;
throwImporError(row,5,"未找到父字典"); throwImporError(row, 5, "未找到父字典");
} }
if(parentItem.getId()==null) { if (parentItem.getId() == null) {
int row = item.getExcelId()+dataStartRow; int row = item.getExcelId() + dataStartRow;
throwImporError(row,5,"父字典未被导入,请先导入父字典"); throwImporError(row, 5, "父字典未被导入,请先导入父字典");
} }
dict.setParent(parentItem.getId()); dict.setParent(parentItem.getId());
} }
dict.setCreateTime(new Date()); dict.setCreateTime(new Date());
//导入前先查找是否有此值 // 导入前先查找是否有此值
CoreDict template = new CoreDict(); CoreDict template = new CoreDict();
template.setType(dict.getType()); template.setType(dict.getType());
template.setValue(dict.getValue()); template.setValue(dict.getValue());
CoreDict dbDict = dictDao.templateOne(template); CoreDict dbDict = dictDao.templateOne(template);
if(dbDict!=null) { if (dbDict != null) {
int row = item.getExcelId()+dataStartRow; int row = item.getExcelId() + dataStartRow;
throwImporError(row,0,"字典数据已经存在"); throwImporError(row, 0, "字典数据已经存在");
} }
dictDao.insert(dict); dictDao.insert(dict);
item.setId(dict.getId()); item.setId(dict.getId());
dataStartRow++; dataStartRow++;
} }
} }
private void throwImporError(int row,int col,String msg) { private void throwImporError(int row, int col, String msg) {
ExcelError error = new ExcelError(); ExcelError error = new ExcelError();
CellReference cr = new CellReference(row,col,false,false); CellReference cr = new CellReference(row, col, false, false);
error.setCell(cr.formatAsString()); error.setCell(cr.formatAsString());
error.setMsg(msg); error.setMsg(msg);
throw new PlatformException("导入错误在:"+error.getCell()+","+msg); throw new PlatformException("导入错误在:" + error.getCell() + "," + msg);
} }
} }
...@@ -22,84 +22,69 @@ import com.ibeetl.admin.core.rbac.tree.FunctionItem; ...@@ -22,84 +22,69 @@ import com.ibeetl.admin.core.rbac.tree.FunctionItem;
import com.ibeetl.admin.core.service.CoreBaseService; import com.ibeetl.admin.core.service.CoreBaseService;
import com.ibeetl.admin.core.service.CorePlatformService; import com.ibeetl.admin.core.service.CorePlatformService;
import com.ibeetl.admin.core.util.PlatformException; import com.ibeetl.admin.core.util.PlatformException;
/** /** @author lijiazhi */
* @author lijiazhi
*
*/
@Service @Service
@Transactional @Transactional
public class FunctionConsoleService extends CoreBaseService<CoreFunction> { public class FunctionConsoleService extends CoreBaseService<CoreFunction> {
@Autowired @Autowired FunctionConsoleDao functionDao;
FunctionConsoleDao functionDao; @Autowired CoreMenuDao menuDao;
@Autowired @Autowired RoleFunctionConsoleDao roleFunctionConsoleDao;
CoreMenuDao menuDao; @Autowired CoreRoleMenuDao sysRoleMenuDao;
@Autowired @Autowired CorePlatformService platformService;
RoleFunctionConsoleDao roleFunctionConsoleDao;
@Autowired
CoreRoleMenuDao sysRoleMenuDao;
@Autowired
CorePlatformService platformService;
public void queryByCondtion(PageQuery<CoreFunction> query) { public void queryByCondtion(PageQuery<CoreFunction> query) {
functionDao.queryByCondtion(query); functionDao.queryByCondtion(query);
List<CoreFunction> list = query.getList(); List<CoreFunction> list = query.getList();
this.queryListAfter(list); this.queryListAfter(list);
//处理父功能名称显示 // 处理父功能名称显示
FunctionItem root = platformService.buildFunction(); FunctionItem root = platformService.buildFunction();
for(CoreFunction function:list) { for (CoreFunction function : list) {
Long parentId = function.getParentId(); Long parentId = function.getParentId();
String name = ""; String name = "";
if(parentId != 0) { if (parentId != 0) {
FunctionItem item = root.findChild(parentId); FunctionItem item = root.findChild(parentId);
name = item!=null?item.getName():""; name = item != null ? item.getName() : "";
} }
function.set("parentFunctionText", name); function.set("parentFunctionText", name);
} }
} }
public Long saveFunction(CoreFunction function) {
public Long saveFunction(CoreFunction function){ functionDao.insert(function, true);
functionDao.insert(function,true);
platformService.clearFunctionCache(); platformService.clearFunctionCache();
return function.getId(); return function.getId();
} }
/**
* 删除功能点,跟菜单有关联的无法删除,删除功能点导致所有缓存都需要更新
/** 删除功能点,跟菜单有关联的无法删除,删除功能点导致所有缓存都需要更新 *
* @param functionId * @param functionId
* @return * @return
*/ */
public void deleteFunction(Long functionId){ public void deleteFunction(Long functionId) {
deleteFunctionId(functionId); deleteFunctionId(functionId);
platformService.clearFunctionCache(); platformService.clearFunctionCache();
} }
public void batchDeleteFunction(List<Long> functionIds) {
public void batchDeleteFunction(List<Long> functionIds){ for (Long id : functionIds) {
for(Long id:functionIds){
deleteFunctionId(id); deleteFunctionId(id);
} }
platformService.clearFunctionCache(); platformService.clearFunctionCache();
} }
public void updateFunction(CoreFunction function) {
public void updateFunction(CoreFunction function){
functionDao.updateById(function); functionDao.updateById(function);
platformService.clearFunctionCache(); platformService.clearFunctionCache();
} }
public CoreFunction getFunction(Long functionId){ public CoreFunction getFunction(Long functionId) {
return functionDao.unique(functionId); return functionDao.unique(functionId);
} }
public CoreFunction getFunction(String code){ public CoreFunction getFunction(String code) {
CoreFunction query = new CoreFunction(); CoreFunction query = new CoreFunction();
query.setCode(code); query.setCode(code);
CoreFunction db = functionDao.templateOne(query); CoreFunction db = functionDao.templateOne(query);
...@@ -108,88 +93,88 @@ public class FunctionConsoleService extends CoreBaseService<CoreFunction> { ...@@ -108,88 +93,88 @@ public class FunctionConsoleService extends CoreBaseService<CoreFunction> {
/** /**
* 得到角色对应的所有功能点 * 得到角色对应的所有功能点
*
* @param roleId * @param roleId
* @return * @return
*/ */
public List<Long> getFunctionByRole(Long roleId){ public List<Long> getFunctionByRole(Long roleId) {
return this.roleFunctionConsoleDao.getFunctionIdByRole(roleId); return this.roleFunctionConsoleDao.getFunctionIdByRole(roleId);
} }
/** /**
* 得到角色对应的所有数据权限功能点 * 得到角色对应的所有数据权限功能点
*
* @param roleId * @param roleId
* @return * @return
*/ */
public List<RoleDataAccessFunction> getQueryFunctionByRole(Long roleId){ public List<RoleDataAccessFunction> getQueryFunctionByRole(Long roleId) {
return this.roleFunctionConsoleDao.getQueryFunctionAndRoleData(roleId); return this.roleFunctionConsoleDao.getQueryFunctionAndRoleData(roleId);
} }
/** /**
* 更新角色对应的功能点所有, * 更新角色对应的功能点所有,
*
* @param roleId * @param roleId
* @param data,必须包含id,和 dataAcerssType,采用模板更新 * @param data,必须包含id,和 dataAcerssType,采用模板更新
*/ */
public void updateFunctionAccessByRole(List<RoleDataAccessFunction> data ){ public void updateFunctionAccessByRole(List<RoleDataAccessFunction> data) {
for(RoleDataAccessFunction fun:data){ for (RoleDataAccessFunction fun : data) {
Long roleId = fun.getRoleId(); Long roleId = fun.getRoleId();
Long functionId = fun.getId(); Long functionId = fun.getId();
int accessType= fun.getDataAccessType(); int accessType = fun.getDataAccessType();
CoreRoleFunction template = new CoreRoleFunction(); CoreRoleFunction template = new CoreRoleFunction();
template.setRoleId(roleId); template.setRoleId(roleId);
template.setFunctionId(functionId); template.setFunctionId(functionId);
CoreRoleFunction ret = roleFunctionConsoleDao.templateOne(template); CoreRoleFunction ret = roleFunctionConsoleDao.templateOne(template);
if(ret!=null) { if (ret != null) {
ret.setDataAccessType(accessType); ret.setDataAccessType(accessType);
roleFunctionConsoleDao.updateById(ret); roleFunctionConsoleDao.updateById(ret);
}else { } else {
template.setDataAccessType(accessType); template.setDataAccessType(accessType);
template.setCreateTime(new Date()); template.setCreateTime(new Date());
roleFunctionConsoleDao.insert(template); roleFunctionConsoleDao.insert(template);
} }
} }
} }
/**
/** 给角色赋予功能同时,根据赋予的功能权限,更新能访问的菜单 * 给角色赋予功能同时,根据赋予的功能权限,更新能访问的菜单
*
* @param adds * @param adds
* @param updates * @param updates
* @param dels * @param dels
* @return 返回增加的项的id,用于前端 * @return 返回增加的项的id,用于前端
*/ */
public void updateSysRoleFunction(Long roleId,List<Long> adds,List<Long> dels){ public void updateSysRoleFunction(Long roleId, List<Long> adds, List<Long> dels) {
for(Long del:dels){ for (Long del : dels) {
//获得功能关联的菜单 // 获得功能关联的菜单
CoreRoleFunction temp = new CoreRoleFunction(); CoreRoleFunction temp = new CoreRoleFunction();
temp.setRoleId(roleId); temp.setRoleId(roleId);
temp.setFunctionId(del); temp.setFunctionId(del);
CoreRoleFunction roleFunction = roleFunctionConsoleDao.templateOne(temp); CoreRoleFunction roleFunction = roleFunctionConsoleDao.templateOne(temp);
if(roleFunction==null){ if (roleFunction == null) {
throw new PlatformException("已经被删除了RoleId="+roleId+" functionId="+del); throw new PlatformException("已经被删除了RoleId=" + roleId + " functionId=" + del);
} }
CoreMenu menu = queryFunctionMenu(roleFunction.getFunctionId()); CoreMenu menu = queryFunctionMenu(roleFunction.getFunctionId());
roleFunctionConsoleDao.deleteById(roleFunction.getId()); roleFunctionConsoleDao.deleteById(roleFunction.getId());
if(menu!=null){ if (menu != null) {
//同时,需要删除与此功能关联的菜单 // 同时,需要删除与此功能关联的菜单
CoreRoleMenu sysRoleMenu = querySysRoleMenu(roleFunction.getRoleId(),menu.getId()); CoreRoleMenu sysRoleMenu = querySysRoleMenu(roleFunction.getRoleId(), menu.getId());
if(sysRoleMenu!=null){ if (sysRoleMenu != null) {
sysRoleMenuDao.deleteById(sysRoleMenu.getId()); sysRoleMenuDao.deleteById(sysRoleMenu.getId());
} }
} }
} }
for (Long add : adds) {
for(Long add:adds){
CoreRoleFunction function = new CoreRoleFunction(); CoreRoleFunction function = new CoreRoleFunction();
function.setCreateTime(new Date()); function.setCreateTime(new Date());
function.setRoleId(roleId); function.setRoleId(roleId);
function.setFunctionId(add); function.setFunctionId(add);
this.sqlManager.insert(function); this.sqlManager.insert(function);
CoreMenu menu = queryFunctionMenu(add); CoreMenu menu = queryFunctionMenu(add);
if(menu!=null){ if (menu != null) {
//同时,需要增加菜单 // 同时,需要增加菜单
CoreRoleMenu roleMenu = new CoreRoleMenu(); CoreRoleMenu roleMenu = new CoreRoleMenu();
roleMenu.setMenuId(menu.getId()); roleMenu.setMenuId(menu.getId());
roleMenu.setRoleId(roleId); roleMenu.setRoleId(roleId);
...@@ -197,54 +182,48 @@ public class FunctionConsoleService extends CoreBaseService<CoreFunction> { ...@@ -197,54 +182,48 @@ public class FunctionConsoleService extends CoreBaseService<CoreFunction> {
} }
} }
//清楚缓存 // 清楚缓存
platformService.clearFunctionCache(); platformService.clearFunctionCache();
} }
private CoreMenu queryFunctionMenu(Long functionId) {
private CoreMenu queryFunctionMenu(Long functionId){
CoreMenu query = new CoreMenu(); CoreMenu query = new CoreMenu();
query.setFunctionId(functionId); query.setFunctionId(functionId);
List<CoreMenu> menus = menuDao.template(query); List<CoreMenu> menus = menuDao.template(query);
return menus.isEmpty()?null:menus.get(0); return menus.isEmpty() ? null : menus.get(0);
} }
private CoreRoleMenu querySysRoleMenu(Long roleId, Long menuId) {
private CoreRoleMenu querySysRoleMenu(Long roleId,Long menuId){ CoreRoleMenu query = new CoreRoleMenu();
CoreRoleMenu query= new CoreRoleMenu();
query.setMenuId(menuId); query.setMenuId(menuId);
query.setRoleId(roleId); query.setRoleId(roleId);
List<CoreRoleMenu> menus = sysRoleMenuDao.template(query); List<CoreRoleMenu> menus = sysRoleMenuDao.template(query);
return menus.isEmpty()?null:menus.get(0); return menus.isEmpty() ? null : menus.get(0);
} }
/** /**
* 删除某一个功能点及其子功能,对应的role-function 需要删除,菜单对应的function需要设置成空 * 删除某一个功能点及其子功能,对应的role-function 需要删除,菜单对应的function需要设置成空
*
* @param functionId * @param functionId
*/ */
private void deleteFunctionId(Long functionId){ private void deleteFunctionId(Long functionId) {
FunctionItem root = platformService.buildFunction(); FunctionItem root = platformService.buildFunction();
FunctionItem fun = root.findChild(functionId); FunctionItem fun = root.findChild(functionId);
List<FunctionItem> all = fun.findAllItem(); List<FunctionItem> all = fun.findAllItem();
//也删除自身 // 也删除自身
all.add(fun); all.add(fun);
realDeleteFunction(all); realDeleteFunction(all);
} }
private void realDeleteFunction(List<FunctionItem> all){ private void realDeleteFunction(List<FunctionItem> all) {
List<Long> ids = new ArrayList<>(all.size()); List<Long> ids = new ArrayList<>(all.size());
for(FunctionItem item:all){ for (FunctionItem item : all) {
ids.add(item.getId()); ids.add(item.getId());
this.functionDao.deleteById(item.getId()); this.functionDao.deleteById(item.getId());
} }
//删除角色和功能的关系 // 删除角色和功能的关系
this.roleFunctionConsoleDao.deleteRoleFunction(ids); this.roleFunctionConsoleDao.deleteRoleFunction(ids);
//设置菜单对应的功能项为空 // 设置菜单对应的功能项为空
menuDao.clearMenuFunction(ids); menuDao.clearMenuFunction(ids);
} }
} }
...@@ -20,13 +20,10 @@ import java.util.List; ...@@ -20,13 +20,10 @@ import java.util.List;
@Transactional @Transactional
public class MenuConsoleService extends CoreBaseService<CoreMenu> { public class MenuConsoleService extends CoreBaseService<CoreMenu> {
@Autowired @Autowired MenuConsoleDao menuDao;
MenuConsoleDao menuDao; @Autowired CoreRoleMenuDao roleMenuDao;
@Autowired
CoreRoleMenuDao roleMenuDao;
@Autowired @Autowired CorePlatformService platformService;
CorePlatformService platformService;
public void queryByCondtion(PageQuery<CoreMenu> query) { public void queryByCondtion(PageQuery<CoreMenu> query) {
menuDao.queryByCondtion(query); menuDao.queryByCondtion(query);
...@@ -67,12 +64,11 @@ public class MenuConsoleService extends CoreBaseService<CoreMenu> { ...@@ -67,12 +64,11 @@ public class MenuConsoleService extends CoreBaseService<CoreMenu> {
return menu; return menu;
} }
private void deleteMenuId(Long menuId) { private void deleteMenuId(Long menuId) {
MenuItem root = platformService.buildMenu(); MenuItem root = platformService.buildMenu();
MenuItem fun = root.findChild(menuId); MenuItem fun = root.findChild(menuId);
List<MenuItem> all = fun.findAllItem(); List<MenuItem> all = fun.findAllItem();
//也删除自身 // 也删除自身
all.add(fun); all.add(fun);
realDeleteMenu(all); realDeleteMenu(all);
} }
...@@ -83,8 +79,7 @@ public class MenuConsoleService extends CoreBaseService<CoreMenu> { ...@@ -83,8 +79,7 @@ public class MenuConsoleService extends CoreBaseService<CoreMenu> {
ids.add(item.getId()); ids.add(item.getId());
this.menuDao.deleteById(item.getId()); this.menuDao.deleteById(item.getId());
} }
//删除角色和菜单的关系 // 删除角色和菜单的关系
roleMenuDao.deleteRoleMenu(ids); roleMenuDao.deleteRoleMenu(ids);
} }
} }
...@@ -16,22 +16,18 @@ import com.ibeetl.admin.core.service.CoreBaseService; ...@@ -16,22 +16,18 @@ import com.ibeetl.admin.core.service.CoreBaseService;
import com.ibeetl.admin.core.service.CorePlatformService; import com.ibeetl.admin.core.service.CorePlatformService;
import com.ibeetl.admin.core.util.PlatformException; import com.ibeetl.admin.core.util.PlatformException;
/** /** @author : xiandafu */
*
* @author : xiandafu
*/
@Service @Service
@Transactional @Transactional
public class OrgConsoleService extends CoreBaseService<CoreOrg> { public class OrgConsoleService extends CoreBaseService<CoreOrg> {
@Autowired @Autowired private OrgConsoleDao orgDao;
private OrgConsoleDao orgDao;
@Autowired @Autowired private CorePlatformService platformService;
private CorePlatformService platformService;
/** /**
* 根据条件查询 * 根据条件查询
*
* @param query * @param query
*/ */
public void queryByCondtion(PageQuery<CoreOrg> query) { public void queryByCondtion(PageQuery<CoreOrg> query) {
...@@ -39,11 +35,11 @@ public class OrgConsoleService extends CoreBaseService<CoreOrg> { ...@@ -39,11 +35,11 @@ public class OrgConsoleService extends CoreBaseService<CoreOrg> {
List<CoreOrg> list = query.getList(); List<CoreOrg> list = query.getList();
queryListAfter(list); queryListAfter(list);
OrgItem root = platformService.buildOrg(); OrgItem root = platformService.buildOrg();
//处理父机构名称显示,没有用sql查询是考虑到跨数据库 // 处理父机构名称显示,没有用sql查询是考虑到跨数据库
for(CoreOrg org:list) { for (CoreOrg org : list) {
Long parentId = org.getParentOrgId(); Long parentId = org.getParentOrgId();
OrgItem item = root.findChild(parentId); OrgItem item = root.findChild(parentId);
String name = item!=null?item.getName():""; String name = item != null ? item.getName() : "";
org.set("parentOrgText", name); org.set("parentOrgText", name);
} }
} }
...@@ -53,14 +49,13 @@ public class OrgConsoleService extends CoreBaseService<CoreOrg> { ...@@ -53,14 +49,13 @@ public class OrgConsoleService extends CoreBaseService<CoreOrg> {
queryListAfter(query.getList()); queryListAfter(query.getList());
} }
/** /**
* 获取机构下面的所以机构 * 获取机构下面的所以机构
*
* @param orgId 机构id * @param orgId 机构id
*/ */
public List<Long> getAllChildIdsByOrgId(Long orgId) { public List<Long> getAllChildIdsByOrgId(Long orgId) {
if (orgId == null) if (orgId == null) return null;
return null;
OrgItem orgItem = platformService.buildOrg().findChild(orgId); OrgItem orgItem = platformService.buildOrg().findChild(orgId);
if (orgItem == null) { if (orgItem == null) {
...@@ -78,17 +73,14 @@ public class OrgConsoleService extends CoreBaseService<CoreOrg> { ...@@ -78,17 +73,14 @@ public class OrgConsoleService extends CoreBaseService<CoreOrg> {
@Override @Override
public boolean deleteById(List<Long> ids) { public boolean deleteById(List<Long> ids) {
OrgItem root = platformService.buildOrg(); OrgItem root = platformService.buildOrg();
//检查子节点 // 检查子节点
for (Long id : ids) { for (Long id : ids) {
OrgItem child = root.findChild(id); OrgItem child = root.findChild(id);
if(child.getChildren().size()!=0){ if (child.getChildren().size() != 0) {
throw new PlatformException("不能删除 "+child.getOrg().getName()+",还包含子机构"); throw new PlatformException("不能删除 " + child.getOrg().getName() + ",还包含子机构");
} }
} }
return super.deleteById(ids); return super.deleteById(ids);
} }
} }
...@@ -24,17 +24,15 @@ import com.ibeetl.admin.core.util.enums.RoleTypeEnum; ...@@ -24,17 +24,15 @@ import com.ibeetl.admin.core.util.enums.RoleTypeEnum;
public class RoleConsoleService extends CoreBaseService<CoreRole> { public class RoleConsoleService extends CoreBaseService<CoreRole> {
private static final Logger LOGGER = LoggerFactory.getLogger(RoleConsoleService.class); private static final Logger LOGGER = LoggerFactory.getLogger(RoleConsoleService.class);
@Autowired @Autowired private RoleConsoleDao roleDao;
private RoleConsoleDao roleDao;
@Autowired @Autowired private SQLManager sqlManager;
private SQLManager sqlManager;
@Autowired @Autowired CorePlatformService platformService;
CorePlatformService platformService;
/** /**
* 获取全部操作角色集合 * 获取全部操作角色集合
*
* @return * @return
*/ */
public List<CoreRole> queryAllPermissionList() { public List<CoreRole> queryAllPermissionList() {
...@@ -45,6 +43,7 @@ public class RoleConsoleService extends CoreBaseService<CoreRole> { ...@@ -45,6 +43,7 @@ public class RoleConsoleService extends CoreBaseService<CoreRole> {
/** /**
* 根据删标记获取全部角色集合 * 根据删标记获取全部角色集合
*
* @param delFlagEnum 删除标记 * @param delFlagEnum 删除标记
* @return * @return
*/ */
...@@ -54,6 +53,7 @@ public class RoleConsoleService extends CoreBaseService<CoreRole> { ...@@ -54,6 +53,7 @@ public class RoleConsoleService extends CoreBaseService<CoreRole> {
/** /**
* 根据条件查询 * 根据条件查询
*
* @param query * @param query
*/ */
public void queryByCondtion(PageQuery query) { public void queryByCondtion(PageQuery query) {
...@@ -61,27 +61,25 @@ public class RoleConsoleService extends CoreBaseService<CoreRole> { ...@@ -61,27 +61,25 @@ public class RoleConsoleService extends CoreBaseService<CoreRole> {
super.queryListAfter(query.getList()); super.queryListAfter(query.getList());
} }
public PageQuery<CoreUser> queryRoleUser(PageQuery query) { public PageQuery<CoreUser> queryRoleUser(PageQuery query) {
OrgItem root = platformService.buildOrg(); OrgItem root = platformService.buildOrg();
PageQuery<CoreUser> ret = roleDao.queryUser(query); PageQuery<CoreUser> ret = roleDao.queryUser(query);
List<CoreUser> list = ret.getList(); List<CoreUser> list = ret.getList();
//从缓存里取出组织机构名称 // 从缓存里取出组织机构名称
for(CoreUser user:list) { for (CoreUser user : list) {
Long orgId = user.getOrgId(); Long orgId = user.getOrgId();
Integer orgId1 = (Integer)user.get("orgId1"); Integer orgId1 = (Integer) user.get("orgId1");
user.set("orgIdText", root.findChild(orgId).getName()); user.set("orgIdText", root.findChild(orgId).getName());
user.set("orgId1Text", root.findChild((long)orgId1).getName()); user.set("orgId1Text", root.findChild((long) orgId1).getName());
} }
//再次处理数据字典 // 再次处理数据字典
this.queryListAfter(list); this.queryListAfter(list);
return ret; return ret;
} }
/** /**
* 根据编号查询 * 根据编号查询
*
* @param code 角色编号 * @param code 角色编号
* @return * @return
*/ */
...@@ -92,7 +90,6 @@ public class RoleConsoleService extends CoreBaseService<CoreRole> { ...@@ -92,7 +90,6 @@ public class RoleConsoleService extends CoreBaseService<CoreRole> {
return role; return role;
} }
public boolean deleteById(List<Long> ids) { public boolean deleteById(List<Long> ids) {
if (ids == null || ids.isEmpty()) { if (ids == null || ids.isEmpty()) {
throw new PlatformException("删除数据ID不能为空"); throw new PlatformException("删除数据ID不能为空");
...@@ -104,8 +101,4 @@ public class RoleConsoleService extends CoreBaseService<CoreRole> { ...@@ -104,8 +101,4 @@ public class RoleConsoleService extends CoreBaseService<CoreRole> {
roleDao.batchDeleteUserRole(ids); roleDao.batchDeleteUserRole(ids);
return true; return true;
} }
} }
...@@ -34,21 +34,14 @@ import com.ibeetl.admin.core.util.enums.GeneralStateEnum; ...@@ -34,21 +34,14 @@ import com.ibeetl.admin.core.util.enums.GeneralStateEnum;
@Transactional @Transactional
public class UserConsoleService extends CoreBaseService<CoreUser> { public class UserConsoleService extends CoreBaseService<CoreUser> {
@Autowired @Autowired UserConsoleDao userDao;
UserConsoleDao userDao;
@Autowired FileService fileService;
@Autowired @Autowired PasswordEncryptService passwordEncryptService;
FileService fileService; @Autowired CoreDictService dictService;
@Autowired @Autowired CorePlatformService platformService;
PasswordEncryptService passwordEncryptService;
@Autowired
CoreDictService dictService;
@Autowired
CorePlatformService platformService;
/** /**
* 根据条件查询 * 根据条件查询
* *
...@@ -76,12 +69,11 @@ public class UserConsoleService extends CoreBaseService<CoreUser> { ...@@ -76,12 +69,11 @@ public class UserConsoleService extends CoreBaseService<CoreUser> {
user.setPassword(passwordEncryptService.password(user.getPassword())); user.setPassword(passwordEncryptService.password(user.getPassword()));
user.setDelFlag(DelFlagEnum.NORMAL.getValue()); user.setDelFlag(DelFlagEnum.NORMAL.getValue());
userDao.insert(user, true); userDao.insert(user, true);
if(StringUtils.isNotEmpty(user.getAttachmentId())){ if (StringUtils.isNotEmpty(user.getAttachmentId())) {
//更新附件详细信息,关联到这个用户 // 更新附件详细信息,关联到这个用户
fileService.updateFile(user.getAttachmentId(), User.class.getSimpleName(), String.valueOf(user.getId())); fileService.updateFile(
user.getAttachmentId(), User.class.getSimpleName(), String.valueOf(user.getId()));
} }
} }
/** /**
...@@ -106,8 +98,7 @@ public class UserConsoleService extends CoreBaseService<CoreUser> { ...@@ -106,8 +98,7 @@ public class UserConsoleService extends CoreBaseService<CoreUser> {
/** /**
* 删除用户 * 删除用户
* *
* @param userId * @param userId 用户id
* 用户id
*/ */
public void delSysUser(Long userId) { public void delSysUser(Long userId) {
CoreUser user = queryUserById(userId); CoreUser user = queryUserById(userId);
...@@ -124,11 +115,10 @@ public class UserConsoleService extends CoreBaseService<CoreUser> { ...@@ -124,11 +115,10 @@ public class UserConsoleService extends CoreBaseService<CoreUser> {
} }
/** /**
* 批量删除用户 <br/> * 批量删除用户 <br>
* 软删除 标记用户删除状态 * 软删除 标记用户删除状态
* *
* @param userIds * @param userIds 用户id
* 用户id
*/ */
public void batchDelSysUser(List<Long> userIds) { public void batchDelSysUser(List<Long> userIds) {
try { try {
...@@ -139,11 +129,10 @@ public class UserConsoleService extends CoreBaseService<CoreUser> { ...@@ -139,11 +129,10 @@ public class UserConsoleService extends CoreBaseService<CoreUser> {
} }
/** /**
* 批量停用用户 <br/> * 批量停用用户 <br>
* 标记用户状态 停用 * 标记用户状态 停用
* *
* @param userIds * @param userIds 用户id
* 用户id
*/ */
public void batchUpdateUserState(List<Long> userIds, GeneralStateEnum stateEnum) { public void batchUpdateUserState(List<Long> userIds, GeneralStateEnum stateEnum) {
userDao.batchUpdateUserState(userIds, stateEnum); userDao.batchUpdateUserState(userIds, stateEnum);
...@@ -164,7 +153,8 @@ public class UserConsoleService extends CoreBaseService<CoreUser> { ...@@ -164,7 +153,8 @@ public class UserConsoleService extends CoreBaseService<CoreUser> {
} }
public List<CoreUserRole> getUserRoles(UserRoleQuery roleQuery) { public List<CoreUserRole> getUserRoles(UserRoleQuery roleQuery) {
return userDao.queryUserRole(roleQuery.getUserId(), roleQuery.getOrgId(), roleQuery.getRoleId()); return userDao.queryUserRole(
roleQuery.getUserId(), roleQuery.getOrgId(), roleQuery.getRoleId());
} }
public void deleteUserRoles(List<Long> ids) { public void deleteUserRoles(List<Long> ids) {
...@@ -172,7 +162,6 @@ public class UserConsoleService extends CoreBaseService<CoreUser> { ...@@ -172,7 +162,6 @@ public class UserConsoleService extends CoreBaseService<CoreUser> {
for (Long id : ids) { for (Long id : ids) {
sqlManager.deleteById(CoreUserRole.class, id); sqlManager.deleteById(CoreUserRole.class, id);
} }
} }
public void saveUserRole(CoreUserRole userRole) { public void saveUserRole(CoreUserRole userRole) {
...@@ -190,26 +179,23 @@ public class UserConsoleService extends CoreBaseService<CoreUser> { ...@@ -190,26 +179,23 @@ public class UserConsoleService extends CoreBaseService<CoreUser> {
List<CoreUser> list = ret.getList(); List<CoreUser> list = ret.getList();
OrgItem orgRoot = platformService.buildOrg(); OrgItem orgRoot = platformService.buildOrg();
List<UserExcelExportData> items = new ArrayList<>(); List<UserExcelExportData> items = new ArrayList<>();
for(CoreUser user:list) { for (CoreUser user : list) {
UserExcelExportData userItem = new UserExcelExportData(); UserExcelExportData userItem = new UserExcelExportData();
userItem.setCode(user.getCode()); userItem.setCode(user.getCode());
userItem.setId(user.getId()); userItem.setId(user.getId());
userItem.setName(user.getName()); userItem.setName(user.getName());
CoreDict dict = dictService.findCoreDict(CoreDictType.USER_STATE,user.getState()); CoreDict dict = dictService.findCoreDict(CoreDictType.USER_STATE, user.getState());
userItem.setStateText(dict.getName()); userItem.setStateText(dict.getName());
if(StringUtils.isNotEmpty(user.getJobType1())){ if (StringUtils.isNotEmpty(user.getJobType1())) {
dict = dictService.findCoreDict("job_type",user.getJobType1()); dict = dictService.findCoreDict("job_type", user.getJobType1());
userItem.setJobType1Text(dict.getName()); userItem.setJobType1Text(dict.getName());
} }
String orgName = orgRoot.findChild(user.getOrgId()).getName(); String orgName = orgRoot.findChild(user.getOrgId()).getName();
userItem.setOrgText(orgName); userItem.setOrgText(orgName);
items.add(userItem); items.add(userItem);
} }
return items; return items;
} }
} }
package com.ibeetl.admin.console.web; package com.ibeetl.admin.console.web;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -25,17 +24,15 @@ import com.ibeetl.admin.core.util.AnnotationUtil; ...@@ -25,17 +24,15 @@ import com.ibeetl.admin.core.util.AnnotationUtil;
import com.ibeetl.admin.core.web.JsonResult; import com.ibeetl.admin.core.web.JsonResult;
/** /**
* 用户管理接口 * 用户管理接口
* @author xiandafu
* *
* @author xiandafu
*/ */
@Controller @Controller
public class AuditConsoleController { public class AuditConsoleController {
private final Log log = LogFactory.getLog(this.getClass()); private final Log log = LogFactory.getLog(this.getClass());
private static final String MODEL = "/admin/audit"; private static final String MODEL = "/admin/audit";
@Autowired @Autowired AuditConsoleService auditConsoleService;
AuditConsoleService auditConsoleService;
/*页面*/ /*页面*/
...@@ -47,7 +44,6 @@ public class AuditConsoleController { ...@@ -47,7 +44,6 @@ public class AuditConsoleController {
return view; return view;
} }
/*Json*/ /*Json*/
@PostMapping(MODEL + "/view.json") @PostMapping(MODEL + "/view.json")
...@@ -58,8 +54,6 @@ public class AuditConsoleController { ...@@ -58,8 +54,6 @@ public class AuditConsoleController {
return JsonResult.success(audit); return JsonResult.success(audit);
} }
@RequestMapping(MODEL + "/list.json") @RequestMapping(MODEL + "/list.json")
@Function("trace") @Function("trace")
@ResponseBody @ResponseBody
...@@ -70,14 +64,12 @@ public class AuditConsoleController { ...@@ -70,14 +64,12 @@ public class AuditConsoleController {
return JsonResult.success(page); return JsonResult.success(page);
} }
@PostMapping(MODEL + "/list/condition.json") @PostMapping(MODEL + "/list/condition.json")
@Function("trace") @Function("trace")
@ResponseBody @ResponseBody
public JsonResult<List<Map<String, Object>>> listCondtion() { public JsonResult<List<Map<String, Object>>> listCondtion() {
List<Map<String, Object>> list = AnnotationUtil.getInstance().getAnnotations(Query.class, AuditQuery.class); List<Map<String, Object>> list =
AnnotationUtil.getInstance().getAnnotations(Query.class, AuditQuery.class);
return JsonResult.success(list); return JsonResult.success(list);
} }
} }
...@@ -45,28 +45,23 @@ import com.ibeetl.admin.core.util.PlatformException; ...@@ -45,28 +45,23 @@ import com.ibeetl.admin.core.util.PlatformException;
import com.ibeetl.admin.core.util.ValidateConfig; import com.ibeetl.admin.core.util.ValidateConfig;
import com.ibeetl.admin.core.web.JsonResult; import com.ibeetl.admin.core.web.JsonResult;
/** /** CoreDict 接口 */
* CoreDict 接口
*/
@Controller @Controller
public class DictConsoleController{ public class DictConsoleController {
private final Log log = LogFactory.getLog(this.getClass()); private final Log log = LogFactory.getLog(this.getClass());
private static final String MODEL = "/admin/dict"; private static final String MODEL = "/admin/dict";
@Autowired private DictConsoleService dictService; @Autowired private DictConsoleService dictService;
@Autowired @Autowired FileService fileService;
FileService fileService;
@Autowired @Autowired CorePlatformService platformService = null;
CorePlatformService platformService = null;
/* 页面 */ /* 页面 */
@GetMapping(MODEL + "/index.do") @GetMapping(MODEL + "/index.do")
@Function("dict.query") @Function("dict.query")
public ModelAndView index() { public ModelAndView index() {
ModelAndView view = new ModelAndView("/admin/dict/index.html") ; ModelAndView view = new ModelAndView("/admin/dict/index.html");
view.addObject("search", CoreDictQuery.class.getName()); view.addObject("search", CoreDictQuery.class.getName());
return view; return view;
} }
...@@ -92,8 +87,7 @@ public class DictConsoleController{ ...@@ -92,8 +87,7 @@ public class DictConsoleController{
@PostMapping(MODEL + "/list.json") @PostMapping(MODEL + "/list.json")
@Function("dict.query") @Function("dict.query")
@ResponseBody @ResponseBody
public JsonResult<PageQuery> list(CoreDictQuery condtion) public JsonResult<PageQuery> list(CoreDictQuery condtion) {
{
PageQuery page = condtion.getPageQuery(); PageQuery page = condtion.getPageQuery();
dictService.queryByCondition(page); dictService.queryByCondition(page);
return JsonResult.success(page); return JsonResult.success(page);
...@@ -102,8 +96,7 @@ public class DictConsoleController{ ...@@ -102,8 +96,7 @@ public class DictConsoleController{
@PostMapping(MODEL + "/add.json") @PostMapping(MODEL + "/add.json")
@Function("dict.add") @Function("dict.add")
@ResponseBody @ResponseBody
public JsonResult add(@Validated(ValidateConfig.ADD.class)CoreDict dict) public JsonResult add(@Validated(ValidateConfig.ADD.class) CoreDict dict) {
{
dict.setCreateTime(new Date()); dict.setCreateTime(new Date());
dictService.save(dict); dictService.save(dict);
platformService.clearDictCache(); platformService.clearDictCache();
...@@ -123,17 +116,14 @@ public class DictConsoleController{ ...@@ -123,17 +116,14 @@ public class DictConsoleController{
} }
} }
@GetMapping(MODEL + "/view.json") @GetMapping(MODEL + "/view.json")
@Function("dict.query") @Function("dict.query")
@ResponseBody @ResponseBody
public JsonResult<CoreDict>queryInfo(Long id) { public JsonResult<CoreDict> queryInfo(Long id) {
CoreDict dict = dictService.queryById(id); CoreDict dict = dictService.queryById(id);
return JsonResult.success(dict); return JsonResult.success(dict);
} }
@PostMapping(MODEL + "/delete.json") @PostMapping(MODEL + "/delete.json")
@Function("dict.delete") @Function("dict.delete")
@ResponseBody @ResponseBody
...@@ -147,17 +137,18 @@ public class DictConsoleController{ ...@@ -147,17 +137,18 @@ public class DictConsoleController{
@PostMapping(MODEL + "/excel/export.json") @PostMapping(MODEL + "/excel/export.json")
@Function("dict.export") @Function("dict.export")
@ResponseBody @ResponseBody
public JsonResult<String> export(HttpServletResponse response,CoreDictQuery condtion) { public JsonResult<String> export(HttpServletResponse response, CoreDictQuery condtion) {
String excelTemplate ="excelTemplates/admin/dict/dict_collection_template.xls"; String excelTemplate = "excelTemplates/admin/dict/dict_collection_template.xls";
PageQuery<CoreUser> page = condtion.getPageQuery(); PageQuery<CoreUser> page = condtion.getPageQuery();
//取出全部符合条件的 // 取出全部符合条件的
page.setPageSize(Integer.MAX_VALUE); page.setPageSize(Integer.MAX_VALUE);
page.setPageNumber(1); page.setPageNumber(1);
page.setTotalRow(Integer.MAX_VALUE); page.setTotalRow(Integer.MAX_VALUE);
List<CoreDict> dicts =dictService.queryExcel(page); List<CoreDict> dicts = dictService.queryExcel(page);
try(InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(excelTemplate)) { try (InputStream is =
if(is==null) { Thread.currentThread().getContextClassLoader().getResourceAsStream(excelTemplate)) {
throw new PlatformException("模板资源不存在:"+excelTemplate); if (is == null) {
throw new PlatformException("模板资源不存在:" + excelTemplate);
} }
FileItem item = fileService.createFileTemp("dict_collection.xls"); FileItem item = fileService.createFileTemp("dict_collection.xls");
OutputStream os = item.openOutpuStream(); OutputStream os = item.openOutpuStream();
...@@ -165,12 +156,11 @@ public class DictConsoleController{ ...@@ -165,12 +156,11 @@ public class DictConsoleController{
context.putVar("dicts", dicts); context.putVar("dicts", dicts);
JxlsHelper.getInstance().processTemplate(is, os, context); JxlsHelper.getInstance().processTemplate(is, os, context);
os.close(); os.close();
//下载参考FileSystemContorller // 下载参考FileSystemContorller
return JsonResult.success(item.getPath()); return JsonResult.success(item.getPath());
} catch (IOException e) { } catch (IOException e) {
throw new PlatformException(e.getMessage()); throw new PlatformException(e.getMessage());
} }
} }
@PostMapping(MODEL + "/excel/import.do") @PostMapping(MODEL + "/excel/import.do")
...@@ -182,42 +172,44 @@ public class DictConsoleController{ ...@@ -182,42 +172,44 @@ public class DictConsoleController{
} }
InputStream ins = file.getInputStream(); InputStream ins = file.getInputStream();
InputStream inputXML = Thread.currentThread().getContextClassLoader().getResourceAsStream("excelTemplates/admin/dict/dict_mapping.xml"); InputStream inputXML =
XLSReader mainReader = ReaderBuilder.buildFromXML( inputXML ); Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("excelTemplates/admin/dict/dict_mapping.xml");
XLSReader mainReader = ReaderBuilder.buildFromXML(inputXML);
InputStream inputXLS = ins; InputStream inputXLS = ins;
List<DictExcelImportData> dicts = new ArrayList<DictExcelImportData>(); List<DictExcelImportData> dicts = new ArrayList<DictExcelImportData>();
Map beans = new HashMap(); Map beans = new HashMap();
beans.put("list", dicts); beans.put("list", dicts);
ReaderConfig.getInstance().setSkipErrors( true ); ReaderConfig.getInstance().setSkipErrors(true);
XLSReadStatus readStatus = mainReader.read( inputXLS, beans); XLSReadStatus readStatus = mainReader.read(inputXLS, beans);
List<XLSReadMessage> errors = readStatus.getReadMessages(); List<XLSReadMessage> errors = readStatus.getReadMessages();
if(!errors.isEmpty()) { if (!errors.isEmpty()) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for(XLSReadMessage msg:errors) { for (XLSReadMessage msg : errors) {
sb.append(parseXLSReadMessage(msg)); sb.append(parseXLSReadMessage(msg));
sb.append(","); sb.append(",");
} }
sb.setLength(sb.length()-1); sb.setLength(sb.length() - 1);
return JsonResult.failMessage("解析excel出错:"+sb.toString()); return JsonResult.failMessage("解析excel出错:" + sb.toString());
} }
// this.dictService.batchInsert(dicts);//layui对话框不能正确处理http 500错误,改成下面方式 // this.dictService.batchInsert(dicts);//layui对话框不能正确处理http 500错误,改成下面方式
// return JsonResult.success(); // return JsonResult.success();
try { try {
this.dictService.batchInsert(dicts); this.dictService.batchInsert(dicts);
return JsonResult.success(); return JsonResult.success();
}catch(Exception ex) { } catch (Exception ex) {
return JsonResult.failMessage(ex.getMessage()); return JsonResult.failMessage(ex.getMessage());
} }
} }
/*xlsReader 设计有问题,还需要通过解析msg知道错误位置在哪里*/ /*xlsReader 设计有问题,还需要通过解析msg知道错误位置在哪里*/
private String parseXLSReadMessage(XLSReadMessage msg) { private String parseXLSReadMessage(XLSReadMessage msg) {
// String message = "Can't read cell " + getCellName(mapping, rowShift) + " on " + cursor.getSheetName() + " spreadsheet"; // String message = "Can't read cell " + getCellName(mapping, rowShift) + " on " +
// cursor.getSheetName() + " spreadsheet";
String str = msg.getMessage(); String str = msg.getMessage();
int start = "Can't read cell ".length(); int start = "Can't read cell ".length();
int end = str.indexOf("on"); int end = str.indexOf("on");
return str.substring(start,end); return str.substring(start, end);
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment