| | |
| | | |
| | | //package com.vci.starter.revision.service; |
| | | |
| | | import com.vci.ubcs.code.bo.TreeWrapperOptions; |
| | | import com.vci.ubcs.code.entity.BaseModel; |
| | | import com.vci.ubcs.com.vci.starter.util.VciBaseUtil; |
| | | import com.vci.ubcs.com.vci.starter.web.pagemodel.Tree; |
| | | import com.vci.ubcs.com.vci.starter.web.service.VciSecretServiceI; |
| | | import com.vci.ubcs.com.vci.starter.web.util.BeanUtilForVCI; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | public class RevisionModelUtil implements VciSecretServiceI { |
| | | |
| | | private Logger logger = LoggerFactory.getLogger(this.getClass()); |
| | | public void copyFromDTOIgnore(Object dto, BaseModel baseModel) { |
| | | VciBaseUtil.alertNotNull(new Object[]{dto, "数据传输对象", baseModel, "数据库中的数据对象"}); |
| | | BaseModel tempModel = new BaseModel(); |
| | |
| | | baseModel.setDescription(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField("description", dto))); |
| | | tempModel = null; |
| | | } |
| | | public <T, R> List<Tree> doList2Trees(List<T> doList, TreeWrapperOptions wrapperOptions, Function<T, R> f) { |
| | | if (CollectionUtils.isEmpty(doList)) { |
| | | return new ArrayList(); |
| | | } else { |
| | | List<Tree> allTree = new ArrayList(); |
| | | List<Tree> children = new ArrayList(); |
| | | Iterator var6 = doList.iterator(); |
| | | |
| | | while(true) { |
| | | while(var6.hasNext()) { |
| | | T doObject = (T) var6.next(); |
| | | Tree tree = new Tree(); |
| | | List<String> oidFieldNames = VciBaseUtil.str2List(wrapperOptions.getOidFieldName()); |
| | | List<String> oidValues = new LinkedList(); |
| | | oidFieldNames.stream().forEach((s) -> { |
| | | oidValues.add(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField(s, doObject))); |
| | | }); |
| | | tree.setOid((String)oidValues.stream().collect(Collectors.joining(wrapperOptions.getOidValueSep()))); |
| | | if (f != null) { |
| | | tree.setText((String)f.apply(doObject)); |
| | | } else { |
| | | List<String> textFieldNames = VciBaseUtil.str2List(wrapperOptions.getTextFieldName()); |
| | | List<String> textValues = new LinkedList(); |
| | | textFieldNames.stream().forEach((s) -> { |
| | | textValues.add(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField(s, doObject))); |
| | | }); |
| | | tree.setText((String)textValues.stream().collect(Collectors.joining(wrapperOptions.getTextValueSep()))); |
| | | } |
| | | |
| | | if (StringUtil.isNotBlank(wrapperOptions.getParentFieldName())) { |
| | | tree.setParentId(VciBaseUtil.getStringValueFromObject(VciBaseUtil.getValueFromField(wrapperOptions.getParentFieldName(), doObject))); |
| | | } |
| | | |
| | | if (wrapperOptions.isAllAttributes()) { |
| | | try { |
| | | tree.setAttributes(VciBaseUtil.objectToMapString(doObject)); |
| | | } catch (Exception var13) { |
| | | if (this.logger.isErrorEnabled()) { |
| | | this.logger.error("把对象转换为map时出现了错误,但是不影响树的展示,对业务可能有影响"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (wrapperOptions.isMultipleSelect() || wrapperOptions.isShowCheckBox()) { |
| | | tree.setShowCheckbox(true); |
| | | } |
| | | |
| | | if (wrapperOptions.getParentOid() == null) { |
| | | wrapperOptions.setParentOid(""); |
| | | } |
| | | |
| | | if (!StringUtil.isBlank(tree.getParentId()) && (!StringUtil.isNotBlank(wrapperOptions.getParentOid()) || !wrapperOptions.getParentOid().equalsIgnoreCase(tree.getParentId()))) { |
| | | children.add(tree); |
| | | } else { |
| | | allTree.add(tree); |
| | | } |
| | | } |
| | | |
| | | (new Tree()).findChild(allTree, children); |
| | | if (allTree.size() <= 0) { |
| | | allTree.addAll(children); |
| | | } |
| | | |
| | | return allTree; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |