| | |
| | | package com.product.face.service; |
| | | |
| | | import cn.hutool.core.map.MapBuilder; |
| | | import cn.hutool.core.map.MapUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.serializer.SerializerFeature; |
| | | import com.google.common.collect.Lists; |
| | | import com.product.admin.service.SystemFaceService; |
| | | 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.exception.BaseException; |
| | | import com.product.core.service.support.AbstractBaseService; |
| | | import com.product.face.config.ErrorCode; |
| | | 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.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Author cheng |
| | |
| | | private SystemFaceService systemFaceService; |
| | | |
| | | @Resource |
| | | private FaceDesignService designService; |
| | | private FaceCacheService faceCacheService; |
| | | |
| | | |
| | | /** |
| | | * 获取表单配置 |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | public Object getFaceListConf(FieldSetEntity fse) { |
| | | String faceUuid = fse.getString(FaceConst.FIELD_FACE_UUID); |
| | | String faceNumber = fse.getString(FaceConst.FIELD_FACE_NUMBER); |
| | |
| | | if (!StringUtils.isEmpty(faceUuid) && StringUtils.isEmpty(faceNumber)) { |
| | | return systemFaceService.getFaceFieldList(faceUuid); |
| | | } |
| | | //根据表单号查询 |
| | | FieldSetEntity faceConf = getBaseDao().getFieldSetByFilter(FaceConst.TABLE_FACE_CONFIG, "face_number=?", new Object[]{faceNumber}, true); |
| | | DataTableEntity fieldPropertyDt = faceConf.getSubDataTable(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY); |
| | | if (DataTableEntity.isEmpty(fieldPropertyDt)) { |
| | | throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL); |
| | | FaceListEntity faceListCache = faceCacheService.getFaceListCache(faceNumber); |
| | | if (faceListCache == null) { |
| | | throw new BaseException(ErrorCode.GET_FACE_CONF_FAIL); |
| | | } |
| | | List<JSONObject> faceControlList = designService.getFaceControlList(fieldPropertyDt); |
| | | JSONObject jsonObject = faceControlList.get(0); |
| | | if (jsonObject == null || jsonObject.isEmpty()) { |
| | | throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL); |
| | | } |
| | | //表格列 |
| | | JSONArray tableColumns = jsonObject.getJSONObject(FaceConst.FIELD_PROPERTY_CONFIG).getJSONArray(FaceConst.CHILDREN); |
| | | if (tableColumns == null || tableColumns.isEmpty()) { |
| | | throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL); |
| | | } |
| | | List<TableColumn> result = Lists.newArrayList(); |
| | | 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 + "%"); |
| | | } |
| | | tableColumn.setField(fieldName); |
| | | tableColumn.setTitle(config.getString(FaceConst.FIELD_PROPERTY_LABEL)); |
| | | result.add(tableColumn); |
| | | } |
| | | |
| | | return result; |
| | | return faceListCache; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws BaseException |
| | | */ |
| | | public String getFaceFormConfig(FieldSetEntity fse) throws BaseException { |
| | | String faceNumber = fse.getString(FaceConst.FIELD_FACE_NUMBER); |
| | | if (StringUtils.isEmpty(faceNumber)) { |
| | | throw new BaseException(ErrorCode.REQUEST_PARAM_ERROR); |
| | | FaceEntity faceFormCache = faceCacheService.getFaceFormCache(fse.getString(FaceConst.FIELD_FACE_NUMBER)); |
| | | if (faceFormCache == null) { |
| | | throw new BaseException(ErrorCode.GET_FACE_CONF_FAIL); |
| | | } |
| | | //根据表单号查询 |
| | | FieldSetEntity faceConf = getBaseDao().getFieldSetByFilter(FaceConst.TABLE_FACE_CONFIG, "face_number=?", new Object[]{faceNumber}, true); |
| | | DataTableEntity fieldPropertyDt = faceConf.getSubDataTable(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY); |
| | | if (DataTableEntity.isEmpty(fieldPropertyDt)) { |
| | | throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL); |
| | | } |
| | | List<JSONObject> faceControlList = designService.getFaceControlList(fieldPropertyDt); |
| | | Map<String, Object> other = new HashMap<>(); |
| | | other.put("drawingList", faceControlList); |
| | | faceConf.getSubData().clear(); |
| | | return BaseUtil.success(faceConf, other); |
| | | return BaseUtil.success(faceFormCache.getData(), MapUtil.builder("drawingList", (Object) faceFormCache.getDrawingList()).map()); |
| | | } |
| | | |
| | | } |