shichongfu
2023-08-21 90be36e53ecac9893bcb780225372ef33f9cd8fa
Merge branch 'master' of http://nonxin.cn:8090/r/product/product-server-mobile-core/V2.0.0

# Conflicts:
# src/main/java/com/product/mobile/core/service/NavBarManagerService.java
已修改1个文件
318 ■■■■ 文件已修改
src/main/java/com/product/mobile/core/service/NavBarManagerService.java 318 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/mobile/core/service/NavBarManagerService.java
@@ -31,172 +31,174 @@
@Service
public class NavBarManagerService extends AbstractBaseService implements INavBarManagerService {
    @Autowired
    QueryFilterService queryFilterService;
    @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 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 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
     * @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)});
    }
    /**
     * 删除配置
     *
     * @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;
    @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 ");
        //使用角色做功能权限限制
    /**
     * 移动端获取导航栏(展示跳转)
     *
     * @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(" b.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 {
                    byte[] fileContent = fileManagerService.getFileContent(file_uuid);
                    String 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)));
        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;
    }
            }
            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;
    }
}