package com.product.mobile.core.service;
|
|
import cn.hutool.core.io.FileUtil;
|
import com.product.common.lang.StringUtils;
|
import com.product.core.entity.DataTableEntity;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.core.exception.BaseException;
|
import com.product.core.service.support.AbstractBaseService;
|
import com.product.core.service.support.QueryFilterService;
|
import com.product.core.spring.context.SpringMVCContextHolder;
|
import com.product.file.service.FileManagerService;
|
import com.product.mobile.core.config.MobileCoreCode;
|
import com.product.mobile.core.config.MobileCoreConst;
|
import com.product.mobile.core.entity.NavBarEntity;
|
import com.product.mobile.core.service.ide.INavBarManagerService;
|
import com.product.module.sys.entity.SystemUser;
|
import com.product.util.BaseUtil;
|
import com.product.util.sf.img4.util.ImageUtil;
|
import org.apache.commons.codec.binary.Base64;
|
import org.json.JSONArray;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.*;
|
|
/**
|
* @Author cheng
|
* @Date 2022/2/22 17:58
|
* @Desc 导航栏管理实现
|
*/
|
@Service
|
public class NavBarManagerService extends AbstractBaseService implements INavBarManagerService {
|
|
@Autowired
|
QueryFilterService queryFilterService;
|
|
/**
|
* 配置列表
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
@Override
|
public DataTableEntity listConfig(FieldSetEntity fse) throws BaseException {
|
String queryFilter = queryFilterService.getQueryFilter(fse);
|
StringBuilder sql = new StringBuilder();
|
sql.append(" SELECT module_category,count(function_uuid) function_count ")
|
.append(" from product_sys_app_nav_bar a ")
|
.append(" group by module_category,module_sequence order by module_sequence");
|
if (!StringUtils.isEmpty(queryFilter)) {
|
sql.insert(0, " SELECT * FROM (");
|
sql.append(") a WHERE ").append(queryFilter);
|
}
|
return getBaseDao().listTable(sql.toString(),
|
new Object[]{}, fse.getInteger(MobileCoreConst.PAGESIZE), fse.getInteger(MobileCoreConst.CPAGE));
|
}
|
|
/**
|
* 配置详情
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
@Override
|
public FieldSetEntity findConfig(FieldSetEntity fse) throws BaseException {
|
String module_category = fse.getString(MobileCoreConst.MODULE_CATEGORY);
|
if (!StringUtils.isEmpty(module_category)) {
|
DataTableEntity dt = getBaseDao().listTable(MobileCoreConst.TABLE_NAV_BAR, "module_category=?", new Object[]{module_category});
|
if (!DataTableEntity.isEmpty(dt)) {
|
fse = new FieldSetEntity();
|
fse.setTableName(MobileCoreConst.TABLE_NAV_BAR);
|
fse.setValue(MobileCoreConst.MODULE_CATEGORY, module_category);
|
fse.setValue(MobileCoreConst.MODULE_SEQUENCE, dt.getString(0, MobileCoreConst.MODULE_SEQUENCE));
|
fse.addSubDataTable(dt);
|
return fse;
|
}
|
}
|
throw new BaseException(MobileCoreCode.FIND_NAV_BAR_CONFIG_FAIL);
|
}
|
|
/**
|
* 保存配置
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
@Override
|
public void saveConfig(FieldSetEntity fse) throws BaseException {
|
DataTableEntity subDataTable = fse.getSubDataTable(MobileCoreConst.TABLE_NAV_BAR);
|
if (DataTableEntity.isEmpty(subDataTable)) {
|
throw new BaseException(MobileCoreCode.SAVE_NAV_BAR_CONFIG_FAIL);
|
}
|
BaseUtil.createCreatorAndCreationTime(fse);
|
for (int i = 0; i < subDataTable.getRows(); i++) {
|
subDataTable.setFieldValue(i, MobileCoreConst.MODULE_CATEGORY, fse.getString(MobileCoreConst.MODULE_CATEGORY));
|
subDataTable.setFieldValue(i, MobileCoreConst.MODULE_SEQUENCE, fse.getString(MobileCoreConst.MODULE_SEQUENCE));
|
subDataTable.setFieldValue(i, MobileCoreConst.UPDATED_BY, fse.getString(MobileCoreConst.UPDATED_BY));
|
subDataTable.setFieldValue(i, MobileCoreConst.CREATED_BY, fse.getString(MobileCoreConst.CREATED_BY));
|
subDataTable.setFieldValue(i, MobileCoreConst.UPDATED_UTC_DATETIME, fse.getString(MobileCoreConst.UPDATED_UTC_DATETIME));
|
subDataTable.setFieldValue(i, MobileCoreConst.CREATED_UTC_DATETIME, fse.getString(MobileCoreConst.CREATED_UTC_DATETIME));
|
}
|
getBaseDao().update(subDataTable);
|
}
|
|
/**
|
* 删除配置
|
*
|
* @param fse
|
* @throws BaseException
|
*/
|
@Override
|
public void delConfig(FieldSetEntity fse) throws BaseException {
|
getBaseDao().delete(fse.getTableName(), "module_category = ?", new Object[]{fse.getString(MobileCoreConst.MODULE_CATEGORY)});
|
}
|
|
@Autowired
|
FileManagerService fileManagerService;
|
|
/**
|
* 移动端获取导航栏(展示跳转)
|
*
|
* @return
|
* @throws BaseException
|
*/
|
@Override
|
public List<Object> getNarBarTree() throws BaseException {
|
SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
|
if (currentUser == null) {
|
return null;
|
}
|
StringBuilder sql = new StringBuilder();
|
sql.append(" SELECT ");
|
sql.append(" a.function_uuid, ");
|
sql.append(" a.nav_bar_img, ");
|
sql.append(" a.nav_bar_name, ");
|
sql.append(" a.module_category, ");
|
sql.append(" b.route_name, ");
|
sql.append(" concat( '/', b.uuid ) path, ");
|
sql.append(" a.uuid, ");
|
sql.append(" a.sequence,a.module_sequence ");
|
sql.append(" FROM ");
|
sql.append(" product_sys_app_nav_bar a ");
|
sql.append(" JOIN product_sys_functions c ON a.function_uuid = c.uuid ");
|
sql.append(" AND c.status_uuid = 1 ");
|
sql.append(" and c.function_type_uuid=1 ");
|
sql.append(" AND concat( ',', c.client_type_uuid, ',' ) LIKE '%,App,%' ");
|
sql.append(" JOIN product_sys_function_buttons b ON a.function_uuid = b.function_uuid ");
|
sql.append(" AND b.button_type = 1 ");
|
sql.append(" AND b.is_main = 1 ");
|
sql.append(" AND b.client_type_uuid = 'App' ");
|
sql.append(" JOIN product_sys_function_permission permission ON concat( ',', permission.button_uuid, ',' ) LIKE concat( ',%', b.uuid, '%,' ) ");
|
sql.append(" JOIN product_sys_role role on role.uuid=permission.role_uuid and role.is_used=1 ");
|
//使用角色做功能权限限制
|
sql.append(" and ").append(BaseUtil.buildQuestionMarkFilter("role.uuid", currentUser.getRoles().split(","), true));
|
sql.append(" GROUP BY a.function_uuid, ");
|
sql.append(" a.nav_bar_img, ");
|
sql.append(" a.nav_bar_name, ");
|
sql.append(" a.module_category, ");
|
sql.append(" a.uuid ,");
|
sql.append(" concat( '/', b.uuid ) ,");
|
sql.append(" a.sequence, ");
|
sql.append(" b.route_name,a.module_sequence ");
|
sql.append(" order by a.module_sequence,a.sequence");
|
DataTableEntity dt = getBaseDao().listTable(sql.toString(), new Object[]{});
|
if (!DataTableEntity.isEmpty(dt)) {
|
Map<String, List<NavBarEntity>> map = new LinkedHashMap<>();
|
for (int i = 0; i < dt.getRows(); i++) {
|
String module_name = dt .getString(i, MobileCoreConst.MODULE_CATEGORY);
|
List<NavBarEntity> navBarEntities = map.get(module_name);
|
if (navBarEntities == null) {
|
navBarEntities = new ArrayList<>();
|
map.put(module_name, navBarEntities);
|
}
|
String file_uuid = dt.getString(i, MobileCoreConst.NAV_BAR_IMG);
|
try {
|
String bytes = null;
|
byte[] fileContent = fileManagerService.getFileContent(file_uuid);
|
if (fileContent != null && fileContent.length > 0) {
|
bytes = Base64.encodeBase64String(fileContent);
|
}
|
dt.setFieldValue(i, MobileCoreConst.NAV_BAR_IMG, bytes);
|
} catch (Exception e) {
|
dt.setFieldValue(i, MobileCoreConst.NAV_BAR_IMG, null);
|
}
|
navBarEntities.add(new NavBarEntity(dt.getFieldSetEntity(i)));
|
|
}
|
List<Object> list = new ArrayList<>();
|
map.forEach((k, v) -> {
|
Map<String, Object> m = new HashMap<>();
|
m.put("name", k);
|
m.put("functions", v);
|
list.add(m);
|
});
|
return list;
|
}
|
return null;
|
}
|
/**
|
* 设备管理
|
* 移动端获取导航栏(展示跳转)
|
*
|
* @return
|
* @throws BaseException
|
*/
|
@Override
|
public List<Object> getDeviceNarBarTree() throws BaseException {
|
SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
|
if (currentUser == null) {
|
return null;
|
}
|
StringBuilder sql = new StringBuilder();
|
sql.append(" SELECT ");
|
sql.append(" a.function_uuid, ");
|
sql.append(" a.nav_bar_img, ");
|
sql.append(" a.nav_bar_name, ");
|
sql.append(" a.module_category, ");
|
sql.append(" b.route_name, ");
|
sql.append(" concat( '/', b.uuid ) path, ");
|
sql.append(" a.uuid, ");
|
sql.append(" a.sequence,a.module_sequence ");
|
sql.append(" FROM ");
|
sql.append(" product_sys_app_nav_bar a ");
|
sql.append(" JOIN product_sys_functions c ON a.function_uuid = c.uuid ");
|
sql.append(" AND c.status_uuid = 1 ");
|
sql.append(" and c.function_type_uuid=1 ");
|
sql.append(" AND concat( ',', c.client_type_uuid, ',' ) LIKE '%,App,%' ");
|
sql.append(" JOIN product_sys_function_buttons b ON a.function_uuid = b.function_uuid ");
|
sql.append(" AND b.button_type = 1 ");
|
sql.append(" AND b.is_main = 1 ");
|
sql.append(" AND b.client_type_uuid = 'App' ");
|
sql.append(" JOIN product_sys_function_permission permission ON concat( ',', permission.button_uuid, ',' ) LIKE concat( ',%', b.uuid, '%,' ) ");
|
sql.append(" JOIN product_sys_role role on role.uuid=permission.role_uuid and role.is_used=1 ");
|
//使用角色做功能权限限制
|
sql.append(" and ").append(BaseUtil.buildQuestionMarkFilter("role.uuid", currentUser.getRoles().split(","), true));
|
//添加设备管理模块过滤条件
|
//sql.append(" and a.module_category='设备管理' ");
|
|
sql.append(" GROUP BY a.function_uuid, ");
|
sql.append(" a.nav_bar_img, ");
|
sql.append(" a.nav_bar_name, ");
|
sql.append(" a.module_category, ");
|
sql.append(" a.uuid ,");
|
sql.append(" concat( '/', b.uuid ) ,");
|
sql.append(" a.sequence, ");
|
sql.append(" b.route_name,a.module_sequence ");
|
sql.append(" order by a.module_sequence,a.sequence");
|
DataTableEntity dt = getBaseDao().listTable(sql.toString(), new Object[]{});
|
if (!DataTableEntity.isEmpty(dt)) {
|
Map<String, List<NavBarEntity>> map = new LinkedHashMap<>();
|
for (int i = 0; i < dt.getRows(); i++) {
|
String module_name = dt .getString(i, MobileCoreConst.MODULE_CATEGORY);
|
List<NavBarEntity> navBarEntities = map.get(module_name);
|
if (navBarEntities == null) {
|
navBarEntities = new ArrayList<>();
|
map.put(module_name, navBarEntities);
|
}
|
String file_uuid = dt.getString(i, MobileCoreConst.NAV_BAR_IMG);
|
try {
|
String bytes = null;
|
byte[] fileContent = fileManagerService.getFileContent(file_uuid);
|
if (fileContent != null && fileContent.length > 0) {
|
bytes = Base64.encodeBase64String(fileContent);
|
}
|
dt.setFieldValue(i, MobileCoreConst.NAV_BAR_IMG, bytes);
|
} catch (Exception e) {
|
dt.setFieldValue(i, MobileCoreConst.NAV_BAR_IMG, null);
|
}
|
navBarEntities.add(new NavBarEntity(dt.getFieldSetEntity(i)));
|
|
}
|
List<Object> list = new ArrayList<>();
|
map.forEach((k, v) -> {
|
Map<String, Object> m = new HashMap<>();
|
m.put("name", k);
|
m.put("functions", v);
|
list.add(m);
|
});
|
return list;
|
}
|
return null;
|
}
|
|
}
|