| | |
| | | @Service |
| | | public class SystemFaceService extends AbstractBaseService implements ISystemFaceService { |
| | | |
| | | /** |
| | | * 缓存起始Key |
| | | */ |
| | | public static final String FACE_LIST_KEY = "face:fieldList:"; |
| | | /** |
| | | * 缓存起始Key |
| | | */ |
| | | public static final String FACE_LIST_KEY = "face:fieldList:"; |
| | | |
| | | |
| | | @Autowired |
| | | QueryFilterService queryFilterService; |
| | | @Autowired |
| | | QueryFilterService queryFilterService; |
| | | |
| | | @Autowired |
| | | RolesService rolesService; |
| | | @Autowired |
| | | RolesService rolesService; |
| | | |
| | | /** |
| | | * 获取模块功能树 |
| | | * |
| | | * @return |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | public DataTableEntity getModuleFunctionTree() throws BaseException { |
| | | /** |
| | | * 获取模块功能树 |
| | | * |
| | | * @return |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | public DataTableEntity getModuleFunctionTree() throws BaseException { |
| | | |
| | | return rolesService.getModuleFunctions(); |
| | | } |
| | | return rolesService.getModuleFunctions(); |
| | | } |
| | | |
| | | /** |
| | | * 表单列表 |
| | | * |
| | | * @param fse |
| | | * @return |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | public DataTableEntity getFaceList(FieldSetEntity fse) throws BaseException { |
| | | String queryFilter = queryFilterService.getQueryFilter(fse); |
| | | String filter = fse.getString("filter"); |
| | | if (StringUtils.isEmpty(filter)) { |
| | | filter = queryFilter; |
| | | } else if (!StringUtils.isEmpty(queryFilter)) { |
| | | filter += " and (" + queryFilter + ") "; |
| | | } |
| | | DataTableEntity dataTableEntity = getBaseDao().listTable(CmnConst.PRODUCT_SYS_FACE, filter, new Object[]{}, null, null, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE)); |
| | | getBaseDao().loadPromptData(dataTableEntity); |
| | | return dataTableEntity; |
| | | } |
| | | /** |
| | | * 表单列表 |
| | | * |
| | | * @param fse |
| | | * @return |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | public DataTableEntity getFaceList(FieldSetEntity fse) throws BaseException { |
| | | String queryFilter = queryFilterService.getQueryFilter(fse); |
| | | String filter = fse.getString("filter"); |
| | | if (StringUtils.isEmpty(filter)) { |
| | | filter = queryFilter; |
| | | } else if (!StringUtils.isEmpty(queryFilter)) { |
| | | filter += " and (" + queryFilter + ") "; |
| | | } |
| | | DataTableEntity dataTableEntity = getBaseDao().listTable(CmnConst.PRODUCT_SYS_FACE, filter, new Object[]{}, null, null, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE)); |
| | | getBaseDao().loadPromptData(dataTableEntity); |
| | | return dataTableEntity; |
| | | } |
| | | |
| | | /** |
| | | * 获取表单详情根据uuid |
| | | * |
| | | * @param fse |
| | | * @return |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | public FieldSetEntity getFaceInfoByUuid(FieldSetEntity fse) throws BaseException { |
| | | return getBaseDao().getFieldSetEntity(CmnConst.PRODUCT_SYS_FACE, fse.getUUID(), true); |
| | | } |
| | | /** |
| | | * 获取表单详情根据uuid |
| | | * |
| | | * @param fse |
| | | * @return |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | public FieldSetEntity getFaceInfoByUuid(FieldSetEntity fse) throws BaseException { |
| | | return getBaseDao().getFieldSetEntity(CmnConst.PRODUCT_SYS_FACE, fse.getUUID(), true); |
| | | } |
| | | |
| | | /** |
| | | * 保存表单详情根据uuid |
| | | * |
| | | * @param fse |
| | | * @return |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public String saveFaceInfo(FieldSetEntity fse) throws BaseException { |
| | | BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse); |
| | | Map<String, DataTableEntity> subData = fse.getSubData(); |
| | | subData.forEach((k, v) -> { |
| | | BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), v); |
| | | }); |
| | | getBaseDao().saveFieldSetEntity(fse); |
| | | this.initialFieldCache(fse.getUUID()); |
| | | return fse.getUUID(); |
| | | } |
| | | /** |
| | | * 保存表单详情根据uuid |
| | | * |
| | | * @param fse |
| | | * @return |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public String saveFaceInfo(FieldSetEntity fse) throws BaseException { |
| | | BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse); |
| | | Map<String, DataTableEntity> subData = fse.getSubData(); |
| | | subData.forEach((k, v) -> { |
| | | BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), v); |
| | | }); |
| | | getBaseDao().saveFieldSetEntity(fse); |
| | | this.initialFieldCache(fse.getUUID()); |
| | | return fse.getUUID(); |
| | | } |
| | | |
| | | /** |
| | | * 删除表单详情根据uuid |
| | | * |
| | | * @param uuids |
| | | * @return |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public boolean deleteFaceInfoByUuids(String[] uuids) throws BaseException { |
| | | boolean delete = getBaseDao().delete(CmnConst.PRODUCT_SYS_FACE, uuids); |
| | | deleteFieldCache(uuids); |
| | | return delete; |
| | | } |
| | | /** |
| | | * 删除表单详情根据uuid |
| | | * |
| | | * @param uuids |
| | | * @return |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public boolean deleteFaceInfoByUuids(String[] uuids) throws BaseException { |
| | | boolean delete = getBaseDao().delete(CmnConst.PRODUCT_SYS_FACE, uuids); |
| | | deleteFieldCache(uuids); |
| | | return delete; |
| | | } |
| | | |
| | | @Override |
| | | public FaceListEntity getFaceFieldList(String face_uuid) throws BaseException { |
| | | if (StringUtils.isEmpty(face_uuid)) { |
| | | return null; |
| | | } |
| | | if (!RedisUtil.exists(this.FACE_LIST_KEY + face_uuid)) { |
| | | this.initialFieldCache(face_uuid); |
| | | } |
| | | FaceListEntity faceListEntity = (FaceListEntity) RedisUtil.get(this.FACE_LIST_KEY + face_uuid); |
| | | if (faceListEntity == null) { |
| | | initialFieldCache(face_uuid); |
| | | faceListEntity = (FaceListEntity) RedisUtil.get(this.FACE_LIST_KEY + face_uuid); |
| | | } |
| | | return faceListEntity; |
| | | } |
| | | @Override |
| | | public FaceListEntity getFaceFieldList(String face_uuid) throws BaseException { |
| | | if (StringUtils.isEmpty(face_uuid)) { |
| | | return null; |
| | | } |
| | | if (!RedisUtil.exists(this.FACE_LIST_KEY + face_uuid)) { |
| | | this.initialFieldCache(face_uuid); |
| | | } |
| | | FaceListEntity faceListEntity = (FaceListEntity) RedisUtil.get(this.FACE_LIST_KEY + face_uuid); |
| | | if (faceListEntity == null) { |
| | | initialFieldCache(face_uuid); |
| | | faceListEntity = (FaceListEntity) RedisUtil.get(this.FACE_LIST_KEY + face_uuid); |
| | | } |
| | | return faceListEntity; |
| | | } |
| | | |
| | | /** |
| | | * 获取列表过滤条件 |
| | | * |
| | | * @param aliasTable 表别名集合 |
| | | * @param face_uuid 表单uuid |
| | | * @param val 模糊搜索值 |
| | | * @return sql过滤条件 |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | public String getListFilter(Map<String, List<String>> aliasTable, Map<String, List<String>> aliasField, String face_uuid, String val) throws BaseException { |
| | | if (StringUtils.isEmpty(val)) { |
| | | return ""; |
| | | } |
| | | FaceListEntity face = (FaceListEntity) RedisUtil.get(this.FACE_LIST_KEY + face_uuid); |
| | | if (face != null) { |
| | | String tableAlias = null; |
| | | String tableName = face.getTableName(); |
| | | List<String> t = aliasTable.get(tableName); |
| | | if (t != null && t.size() > 0) { |
| | | tableAlias = t.get(0); |
| | | } |
| | | Map<String, List<String>> params = face.getFilters(tableAlias, aliasField); |
| | | List<String> fieldNames = params.get("fields"); |
| | | List<String> filters = params.get("filter"); |
| | | String filter = ""; |
| | | for (int i = 0; i < fieldNames.size(); i++) { |
| | | if (i > 0) { |
| | | filter += " or "; |
| | | } |
| | | filter += " " + fieldNames.get(i) + " LIKE BINARY concat('%','" + val + "','%')"; |
| | | } |
| | | for (int i = 0; i < filters.size(); i++) { |
| | | if (!"".equals(filter)) { |
| | | filter += " or "; |
| | | } |
| | | filter += filters.get(i).replace("~val~", val); |
| | | } |
| | | return "".equals(filter) ? "" : "( " + filter + " )"; |
| | | } |
| | | return ""; |
| | | } |
| | | /** |
| | | * 获取列表过滤条件 |
| | | * |
| | | * @param aliasTable 表别名集合 |
| | | * @param face_uuid 表单uuid |
| | | * @param val 模糊搜索值 |
| | | * @return sql过滤条件 |
| | | * @throws BaseException |
| | | */ |
| | | @Override |
| | | public String getListFilter(Map<String, List<String>> aliasTable, Map<String, List<String>> aliasField, String face_uuid, String val) throws BaseException { |
| | | if (StringUtils.isEmpty(val)) { |
| | | return ""; |
| | | } |
| | | FaceListEntity face = (FaceListEntity) RedisUtil.get(this.FACE_LIST_KEY + face_uuid); |
| | | if (face != null) { |
| | | String tableAlias = null; |
| | | String tableName = face.getTableName(); |
| | | List<String> t = aliasTable.get(tableName); |
| | | if (t != null && t.size() > 0) { |
| | | tableAlias = t.get(0); |
| | | } |
| | | Map<String, List<String>> params = face.getFilters(tableAlias, aliasField); |
| | | List<String> fieldNames = params.get("fields"); |
| | | List<String> filters = params.get("filter"); |
| | | String filter = ""; |
| | | for (int i = 0; i < fieldNames.size(); i++) { |
| | | if (i > 0) { |
| | | filter += " or "; |
| | | } |
| | | filter += " " + fieldNames.get(i) + " LIKE BINARY concat('%','" + val + "','%')"; |
| | | } |
| | | for (int i = 0; i < filters.size(); i++) { |
| | | if (!"".equals(filter)) { |
| | | filter += " or "; |
| | | } |
| | | filter += filters.get(i).replace("~val~", val); |
| | | } |
| | | return "".equals(filter) ? "" : "( " + filter + " )"; |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | /** |
| | | * 删除表单字段缓存根据表单uuid |
| | | * |
| | | * @param uuid |
| | | */ |
| | | private void deleteFieldCache(String[] uuid) { |
| | | if (uuid != null && uuid.length > 0) { |
| | | String[] keys = new String[uuid.length]; |
| | | for (int i = 0; i < uuid.length; i++) { |
| | | keys[i] = this.FACE_LIST_KEY + uuid[i]; |
| | | } |
| | | if (keys.length > 0) { |
| | | RedisUtil.del(keys); |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 删除表单字段缓存根据表单uuid |
| | | * |
| | | * @param uuid |
| | | */ |
| | | private void deleteFieldCache(String[] uuid) { |
| | | if (uuid != null && uuid.length > 0) { |
| | | String[] keys = new String[uuid.length]; |
| | | for (int i = 0; i < uuid.length; i++) { |
| | | keys[i] = this.FACE_LIST_KEY + uuid[i]; |
| | | } |
| | | if (keys.length > 0) { |
| | | RedisUtil.del(keys); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 初始化表单字段缓存 |
| | | * |
| | | * @param faceUuids 表单uuid 多个用逗号分割 传入null 则初始化所有 |
| | | */ |
| | | private void initialFieldCache(String faceUuids) { |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append(" SELECT "); |
| | | sql.append(" ifnull(d.field_name,a.field_name) field_name,a.field_alias, "); |
| | | sql.append(" d.field_reference, "); |
| | | sql.append(" d.uuid field_uuid, "); |
| | | sql.append(" b.face_name, "); |
| | | sql.append(" b.table_uuid, "); |
| | | sql.append(" a.face_uuid, "); |
| | | sql.append(" column_name, "); |
| | | sql.append(" column_width, "); |
| | | sql.append(" sequence "); |
| | | sql.append(" FROM "); |
| | | sql.append(" product_sys_face_list a "); |
| | | sql.append(" RIGHT JOIN product_sys_face b ON a.face_uuid = b.uuid "); |
| | | sql.append(" LEFT JOIN product_sys_datamodel_field d ON a.field_name = d.field_name and b.table_uuid=d.table_uuid"); |
| | | sql.append(" WHERE "); |
| | | sql.append(" a.is_used = 1 "); |
| | | Object[] objects = {}; |
| | | if (!StringUtils.isEmpty(faceUuids)) { |
| | | sql.append(" AND ( "); |
| | | objects = faceUuids.split(","); |
| | | sql.append(BaseUtil.buildQuestionMarkFilter("b.uuid", objects.length, true)); |
| | | sql.append(" ) "); |
| | | } |
| | | sql.append(" ORDER BY face_uuid,sequence "); |
| | | DataTableEntity dt = getBaseDao().listTable(sql.toString(), objects); |
| | | Map<String, FaceListEntity> faceListEntityMap = Maps.newHashMap(); |
| | | if (!BaseUtil.dataTableIsEmpty(dt)) { |
| | | for (int i = 0; i < dt.getRows(); i++) { |
| | | String face_uuid = dt.getString(i, "face_uuid"); |
| | | FaceListEntity faceListEntity = faceListEntityMap.get(face_uuid); |
| | | if (faceListEntity == null) { |
| | | faceListEntity = new FaceListEntity(); |
| | | faceListEntity.setFaceName(face_uuid); |
| | | faceListEntity.setTableUuid(dt.getString(i, CmnConst.TABLE_UUID)); |
| | | faceListEntity.setUuid(dt.getString(i, "face_uuid")); |
| | | faceListEntityMap.put(face_uuid, faceListEntity); |
| | | } |
| | | faceListEntity.addField(dt.getString(i, CmnConst.FIELD_NAME), dt.getString(i, "field_uuid"), |
| | | dt.getString(i, "column_name"), |
| | | dt.getString(i, "column_width"), |
| | | dt.getInt(i, CmnConst.SEQUENCE), dt.getString(i, "field_reference")); |
| | | /** |
| | | * 初始化表单字段缓存 |
| | | * |
| | | * @param faceUuids 表单uuid 多个用逗号分割 传入null 则初始化所有 |
| | | */ |
| | | private void initialFieldCache(String faceUuids) { |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append(" SELECT "); |
| | | sql.append(" ifnull(d.field_name,a.field_name) field_name,a.field_alias, "); |
| | | sql.append(" d.field_reference, "); |
| | | sql.append(" d.uuid field_uuid, "); |
| | | sql.append(" b.face_name, "); |
| | | sql.append(" b.table_uuid, "); |
| | | sql.append(" a.face_uuid, "); |
| | | sql.append(" column_name, "); |
| | | sql.append(" column_width, "); |
| | | sql.append(" sequence "); |
| | | sql.append(" FROM "); |
| | | sql.append(" product_sys_face_list a "); |
| | | sql.append(" RIGHT JOIN product_sys_face b ON a.face_uuid = b.uuid "); |
| | | sql.append(" LEFT JOIN product_sys_datamodel_field d ON a.field_name = d.field_name and b.table_uuid=d.table_uuid"); |
| | | sql.append(" WHERE "); |
| | | sql.append(" a.is_used = 1 "); |
| | | Object[] objects = {}; |
| | | if (!StringUtils.isEmpty(faceUuids)) { |
| | | sql.append(" AND ( "); |
| | | objects = faceUuids.split(","); |
| | | sql.append(BaseUtil.buildQuestionMarkFilter("b.uuid", objects.length, true)); |
| | | sql.append(" ) "); |
| | | } |
| | | sql.append(" ORDER BY face_uuid,sequence "); |
| | | DataTableEntity dt = getBaseDao().listTable(sql.toString(), objects); |
| | | Map<String, FaceListEntity> faceListEntityMap = Maps.newHashMap(); |
| | | if (!BaseUtil.dataTableIsEmpty(dt)) { |
| | | for (int i = 0; i < dt.getRows(); i++) { |
| | | String face_uuid = dt.getString(i, "face_uuid"); |
| | | FaceListEntity faceListEntity = faceListEntityMap.get(face_uuid); |
| | | if (faceListEntity == null) { |
| | | faceListEntity = new FaceListEntity(); |
| | | faceListEntity.setFaceName(face_uuid); |
| | | faceListEntity.setTableUuid(dt.getString(i, CmnConst.TABLE_UUID)); |
| | | faceListEntity.setUuid(dt.getString(i, "face_uuid")); |
| | | faceListEntityMap.put(face_uuid, faceListEntity); |
| | | } |
| | | faceListEntity.addField(dt.getString(i, CmnConst.FIELD_NAME), dt.getString(i, "field_uuid"), |
| | | dt.getString(i, "column_name"), |
| | | dt.getString(i, "column_width"), |
| | | dt.getInt(i, CmnConst.SEQUENCE), dt.getString(i, "field_reference")); |
| | | |
| | | } |
| | | if (faceListEntityMap.size() > 0) { |
| | | faceListEntityMap.forEach((f, m) -> { |
| | | RedisUtil.set(FACE_LIST_KEY + m.getUuid(), m); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (faceListEntityMap.size() > 0) { |
| | | faceListEntityMap.forEach((f, m) -> { |
| | | RedisUtil.set(FACE_LIST_KEY + m.getUuid(), m); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |