| | |
| | | package com.product.face.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.common.collect.Lists; |
| | | import com.product.common.lang.StringUtils; |
| | | import com.product.core.cache.util.RedisUtil; |
| | | import com.product.core.entity.DataTableEntity; |
| | | import com.product.core.entity.FieldSetEntity; |
| | | import com.product.core.service.support.AbstractBaseService; |
| | | import com.product.face.config.FaceConst; |
| | | import com.product.face.entity.FaceEntity; |
| | | import com.product.face.entity.FaceListEntity; |
| | | import com.product.face.entity.TableColumn; |
| | | import com.product.face.util.FaceUtil; |
| | | import com.product.util.BaseUtil; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author cheng |
| | |
| | | @Service |
| | | public class FaceCacheService extends AbstractBaseService { |
| | | |
| | | public final static String FACE_CACHE_KEY = "system:face:"; |
| | | |
| | | /** |
| | | * 刷新表单缓存(core调用) |
| | | */ |
| | | public void refreshCache() { |
| | | |
| | | this.loadingCache(null); |
| | | } |
| | | |
| | | /** |
| | | * 刷新表单缓存(core调用) |
| | | * |
| | | * @param uuid |
| | | */ |
| | | public void refreshCache(String uuid) { |
| | | |
| | | this.loadingCache(uuid); |
| | | } |
| | | |
| | | /** |
| | | * 系统加载表单缓存 |
| | | * |
| | | * @param uuid |
| | | */ |
| | | private void loadingCache(String uuid) { |
| | | String filter = BaseUtil.ifNotNull(uuid, (val) -> "uuid=?"); |
| | | Object[] objects = null; |
| | | if (!StringUtils.isEmpty(uuid)) { |
| | | objects = new Object[]{uuid}; |
| | | } |
| | | DataTableEntity dt = getBaseDao().listTable(FaceConst.TABLE_FACE_CONFIG, filter, objects, null, null, Integer.MAX_VALUE, 1, true); |
| | | if (DataTableEntity.isEmpty(dt)) { |
| | | return; |
| | | } |
| | | for (FieldSetEntity fs : dt.getData()) { |
| | | String faceType = fs.getString(FaceConst.FIELD_FACE_TYPE); |
| | | if (StringUtils.isEmpty(faceType)) { |
| | | continue; |
| | | } |
| | | String faceNumber = fs.getString(FaceConst.FIELD_FACE_NUMBER); |
| | | if (StringUtils.isEmpty(faceNumber)) { |
| | | continue; |
| | | } |
| | | if ("2".equals(faceType)) { |
| | | //表单 |
| | | loadingFormCache(fs); |
| | | } else if ("1".equals(faceType)) { |
| | | //列表 |
| | | loadingListCache(fs); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取列表缓存 |
| | | * |
| | | * @param faceNumber |
| | | * @return |
| | | */ |
| | | public FaceListEntity getFaceListCache(String faceNumber) { |
| | | if (StringUtils.isEmpty(faceNumber)) { |
| | | return null; |
| | | } |
| | | final String faceListKey = FaceConst.FACE_LIST_KEY + ":face-number" + faceNumber; |
| | | return (FaceListEntity) RedisUtil.get(faceListKey); |
| | | } |
| | | |
| | | /** |
| | | * 获取表单缓存 |
| | | * |
| | | * @param faceNumber |
| | | * @return |
| | | */ |
| | | public FaceEntity getFaceFormCache(String faceNumber) { |
| | | if (StringUtils.isEmpty(faceNumber)) { |
| | | return null; |
| | | } |
| | | return (FaceEntity) RedisUtil.get(FaceConst.FACE_FORM_CACHE_KEY + faceNumber); |
| | | } |
| | | |
| | | /** |
| | | * 加载表单缓存 |
| | | * |
| | | * @param fse |
| | | */ |
| | | public void loadingFormCache(FieldSetEntity fse) { |
| | | DataTableEntity fieldPropertyDt = fse.getSubDataTable(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY); |
| | | if (DataTableEntity.isEmpty(fieldPropertyDt)) { |
| | | return; |
| | | } |
| | | fse.getSubData().clear(); |
| | | String faceNumber = fse.getString(FaceConst.FIELD_FACE_NUMBER); |
| | | List<JSONObject> faceControlList = FaceUtil.getFaceControlList(fieldPropertyDt); |
| | | if (faceControlList != null) { |
| | | FaceEntity face = new FaceEntity(); |
| | | face.setData(BaseUtil.fieldSetEntityToJson(fse)); |
| | | face.setDrawingList(faceControlList); |
| | | RedisUtil.set(FaceConst.FACE_FORM_CACHE_KEY + faceNumber, face); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 加载列表缓存 |
| | | * |
| | | * @param fse |
| | | */ |
| | | public void loadingListCache(FieldSetEntity fse) { |
| | | DataTableEntity fieldPropertyDt = fse.getSubDataTable(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY); |
| | | if (DataTableEntity.isEmpty(fieldPropertyDt)) { |
| | | return; |
| | | } |
| | | List<JSONObject> faceControlList = FaceUtil.getFaceControlList(fieldPropertyDt); |
| | | JSONObject jsonObject = faceControlList.get(0); |
| | | if (jsonObject == null || jsonObject.isEmpty()) { |
| | | return; |
| | | } |
| | | //表格列 |
| | | JSONArray tableColumns = jsonObject.getJSONObject(FaceConst.FIELD_PROPERTY_CONFIG).getJSONArray(FaceConst.CHILDREN); |
| | | if (tableColumns == null || tableColumns.isEmpty()) { |
| | | return; |
| | | } |
| | | String faceNumber = fse.getString(FaceConst.FIELD_FACE_NUMBER); |
| | | String tableUuid = fse.getString(FaceConst.FIELD_TABLE_UUID); |
| | | List<TableColumn> result = Lists.newArrayList(); |
| | | FaceListEntity faceListEntity = new FaceListEntity(); |
| | | faceListEntity.setFaceName(faceNumber); |
| | | faceListEntity.setTableUuid(tableUuid); |
| | | faceListEntity.setUuid(fse.getUUID()); |
| | | for (int i = 0; i < tableColumns.size(); i++) { |
| | | TableColumn tableColumn = new TableColumn(); |
| | | JSONObject columnJson = tableColumns.getJSONObject(i); |
| | | String fieldName = columnJson.getString(FaceConst.FIELD_PROPERTY_VMODEL); |
| | | if (StringUtils.isEmpty(fieldName)) { |
| | | continue; |
| | | } |
| | | |
| | | |
| | | JSONObject config = columnJson.getJSONObject(FaceConst.FIELD_PROPERTY_CONFIG); |
| | | |
| | | Object setWidth = config.get("setWidth"); |
| | | if (!StringUtils.isEmpty(setWidth)) { |
| | | tableColumn.setColumnWidth(setWidth + "%"); |
| | | } |
| | | FieldSetEntity fieldInfo = BaseUtil.getSingleInfoByCache("表字段信息", new String[]{tableUuid, fieldName}); |
| | | String label = config.getString(FaceConst.FIELD_PROPERTY_LABEL); |
| | | String fieldUuid = null; |
| | | String fieldReference = null; |
| | | if (!FieldSetEntity.isEmpty(fieldInfo)) { |
| | | fieldUuid = fieldInfo.getString(FaceConst.UUID); |
| | | fieldReference = fieldInfo.getString(FaceConst.FIELD_FIELD_REFERENCE); |
| | | } |
| | | faceListEntity.addField(fieldName, fieldUuid, label, tableColumn.getColumnWidth(), i, fieldReference); |
| | | tableColumn.setField(fieldName); |
| | | tableColumn.setTitle(config.getString(FaceConst.FIELD_PROPERTY_LABEL)); |
| | | result.add(tableColumn); |
| | | } |
| | | //验证表单中的字段是否存在 |
| | | if (faceListEntity != null && !CollectionUtil.isEmpty(faceListEntity.getFaceFields())) { |
| | | RedisUtil.set(FaceConst.FACE_LIST_KEY + ":face-number" + faceNumber, faceListEntity); |
| | | } |
| | | } |
| | | |
| | | } |