EvaluationContentComposite.java 9.43 KB
package com.gx.obe.struct.composite;

import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.widgets.ELink;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import com.gx.obe.ColorConstants;
import com.gx.obe.bind.prop.Prop;
import com.gx.obe.common.widget.button.RectangleRadioButton;
import com.gx.obe.component.handler.TabHandler;
import com.gx.obe.component.rx.RxSwt;
import com.gx.obe.components.core.Constants;
import com.gx.obe.components.core.global.Global;
import com.gx.obe.components.core.inter.PdfFileView;
import com.gx.obe.struct.beans.ModelData;
import com.gx.obe.struct.enums.DataCategoryEnum;
import com.gx.obe.struct.enums.EvaluationFactorTypeEnum;
import com.gx.obe.struct.enums.ModelDataTypeEnum;
import com.gx.obe.struct.handler.RelChapterTypeHandler;
import com.gx.obe.struct.parse.BidFileIndexTreeXmlParse;
import com.gx.obe.struct.service.EvaluationContentService;
import com.gx.obe.struct.service.ModelDataService;
import com.gx.obe.util.utils.CollectionUtils;
import com.gx.obe.web.entity.evaluation.EvaluationContent;
import com.swtdesigner.SWTResourceManager;

public class EvaluationContentComposite extends Composite {
	
	private final EvaluationContentService evaluationContentService = new EvaluationContentService();
	private final ModelDataService modelDataService = new ModelDataService();
	
	private final String tenderId;
	
	private final Prop<EvaluationContentData> evaluationContentData = new Prop<>();
	private final Prop<PdfFileData> pdfFileData = new Prop<>();
	private final Prop<String> tips = new Prop<>();
	
	private final Prop<Boolean> showFile = new Prop<>();
	private final Prop<Boolean> showSwitch = new Prop<>(false);
	
	private class RootNodeChapterData {
		private String name;
		private String type;
	}
	
	private class EvaluationContentData {
		private String supplierId;
		private EvaluationFactorTypeEnum factorTypeEnum;
		private List<EvaluationContent> evaluationContentList;
	}
	
	private class PdfFileData {
		private String url;
		private int pageNum;
	}
	
	public EvaluationContentComposite(Composite parent, String tenderId) {
		super(parent, SWT.NONE);
		this.tenderId = tenderId;
		
		setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		setBackgroundMode(SWT.INHERIT_FORCE);
		GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.verticalSpacing = 0;
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		setLayout(gridLayout);
		
		Composite composite_5 = new Composite(this, SWT.NONE);
		composite_5.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		GridLayout gl_composite_5 = new GridLayout(2, false);
		gl_composite_5.marginHeight = 0;
		gl_composite_5.marginWidth = 0;
		composite_5.setLayout(gl_composite_5);
		
		Composite composite = new Composite(composite_5, SWT.NONE);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, true, 1, 1));
		RowLayout rl_composite = new RowLayout(SWT.HORIZONTAL);
		rl_composite.marginBottom = 0;
		rl_composite.marginTop = 0;
		composite.setLayout(rl_composite);
		
		TabHandler<RectangleRadioButton> handler = new TabHandler<>(composite, t -> new RectangleRadioButton(t, SWT.NONE));
		
		Composite composite_6 = new Composite(composite_5, SWT.NONE);
		GridLayout gl_composite_6 = new GridLayout(1, false);
		gl_composite_6.marginHeight = 4;
		composite_6.setLayout(gl_composite_6);
		
		ELink link = new ELink(composite_6, SWT.NONE);
		link.addMouseListener(MouseListener.mouseUpAdapter($ -> showFile.replace(t -> !t)));
		link.setText("切换视图");
		showSwitch.bind(link::setVisible);
		
		ESepator label_1 = new ESepator(this, SWT.HORIZONTAL);
		label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		label_1.setBackground(ColorConstants.SKIN_BG);
		
		StackLayout stackLayout = new StackLayout();
		
		Composite composite_1 = new Composite(this, SWT.NONE);
		composite_1.setLayout(stackLayout);
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		Consumer<Composite> topControl = t -> {
			stackLayout.topControl = t;
			composite_1.layout();
		};
		
		ModelDataComposite composite_2 = new ModelDataComposite(composite_1, tenderId);
		
		Composite composite_3 = new Composite(composite_1, SWT.NONE);
		composite_3.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		PdfFileView load = Global.PDF_FILE_VIEW.load(composite_3, SWT.NONE);
		load.setFileNotExistMessage("文件不存在,请检查是否已下载投标文件!");
		pdfFileData.bind(t -> load.openFile(t.url, t.pageNum));
		
		Composite composite_4 = new Composite(composite_1, SWT.NONE);
		composite_4.setLayout(new GridLayout(1, false));
		
		Label label = new Label(composite_4, SWT.WRAP);
		label.setForeground(SWTResourceManager.getColor(200, 200, 200));
		label.setFont(SWTResourceManager.getFont("宋体", 20, SWT.BOLD));
		label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 1));
		
		tips.bind(t -> {
			label.setText(t);
			label.getParent().layout();
		});
		
		showFile.bind(t -> {
			if (t) topControl.accept(composite_3);
			else topControl.accept(composite_2);
		});
		
		evaluationContentData.bind(d -> {
			showSwitch.set(false);
			handler.start();
			if (CollectionUtils.isNull(d.evaluationContentList)) {
				rootNodeChapter(handler, d.factorTypeEnum, t -> {
					showFile.set(true);
					RxSwt.run(() -> getFilePath(d.supplierId, t.type)).checkWidget(this).exe(pdfFileData::set);
				});
			} else {
				handler.listHand(d.evaluationContentList, EvaluationContent::getEvalPointName, t -> {
					showSwitch.set(false);
					switch (DataCategoryEnum.MAP.getOrDefault(t.getDataCategory(), DataCategoryEnum.NULL)) {
						case MD:
							getModelData(t.getRelChapterType(), d.supplierId, md -> {
								if (md == null) {
									topControl.accept(composite_4);
									tips.set("当前供应商未检测到" + t.getEvalPointName() + ",请检查是否已解析结构化数据!");
								} else {
									if (ModelDataTypeEnum.EQ_ProjectLeader.getKey().equals(md.getRelChapterType())) {
										showSwitch.set(true);
										showFile.set(false);
										composite_2.refresh(t, md);
										RxSwt.run(() -> getFilePath(d.supplierId, "EnterpriseQualification_technology")).checkWidget(this).exe(pdfFileData::set);
									} else {
										showFile.set(false);
										composite_2.refresh(t, md);
									}
								}
							});
							break;
						case TDI:
						case TT:
						case NULL:
							showFile.set(true);
							RxSwt.run(() -> getFilePath(d.supplierId, t.getRelChapterType())).checkWidget(this).exe(pdfFileData::set);
							break;
					}
				});
			}
			handler.end();
		});
	}
	
	private void rootNodeChapter(TabHandler<RectangleRadioButton> handler, EvaluationFactorTypeEnum factorTypeEnum, Consumer<RootNodeChapterData> callback) {
		handler.listHand(initRootNodeChapterList(factorTypeEnum).map(t -> {
			String[] split = t.split("-", 2);
			RootNodeChapterData chapterData = new RootNodeChapterData();
			chapterData.type = split[0];
			chapterData.name = split[1];
			return chapterData;
		}).collect(Collectors.toList()), t -> t.name, callback);
	}
	
	private void getModelData(String _relChapterType, String supplierId, Consumer<ModelData> consumer) {
		RelChapterTypeHandler typeHandler = new RelChapterTypeHandler(_relChapterType);
		Optional<ModelDataTypeEnum> modelDataTypeEnum = Optional.of(typeHandler.getRelChapterType()).map(ModelDataTypeEnum.MAP::get);
		String relChapterType = modelDataTypeEnum.map(ModelDataTypeEnum.EQ_ProjectLeader::equals).orElse(false) ? typeHandler.getRelChapterType() : _relChapterType;
		RxSwt.run(() -> modelDataService.getModelData(tenderId, supplierId, relChapterType, relChapterType)).checkWidget(this).exe(consumer);
	}
	
	private Stream<String> initRootNodeChapterList(EvaluationFactorTypeEnum factorTypeEnum) {
		if (EvaluationFactorTypeEnum.BUSINESS == factorTypeEnum) {
			return Stream.of("Business-商务标");
		}
		if (EvaluationFactorTypeEnum.TECHNOLOGY == factorTypeEnum) {
			return Stream.of("Technology-技术标");
		}
		return Stream.of("Business-商务标", "Technology-技术标", "Price-报价");
	}
	
	public void refresh(String supplierId, String factorCode, EvaluationFactorTypeEnum factorTypeEnum) {
		RxSwt.run(() -> {
			EvaluationContentData evaluationContentData = new EvaluationContentData();
			evaluationContentData.supplierId = supplierId;
			evaluationContentData.factorTypeEnum = factorTypeEnum;
			evaluationContentData.evaluationContentList = evaluationContentService.getEvaluationContentListByFactorCode(tenderId, factorCode);
			return evaluationContentData;
		}).checkWidget(this).exe(evaluationContentData::set);
	}
	
	private PdfFileData getFilePath(String supplierId, String relChapterType) {
		BidFileIndexTreeXmlParse bidFileIndexTreeXmlParse = new BidFileIndexTreeXmlParse(Constants.getBidFilePath(tenderId, supplierId), relChapterType);
		PdfFileData pdfFileData = new PdfFileData();
		pdfFileData.url = bidFileIndexTreeXmlParse.getRootNodeFilePath();
		pdfFileData.pageNum = bidFileIndexTreeXmlParse.getPageNumInGenerateFile();
		return pdfFileData;
	}
	
	@Override
	protected void checkSubclass() {}
	
}