package nckd.jxccl.hr.hstu.plugin.operate.validate;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.validate.AbstractValidator;
import nckd.jxccl.base.common.utils.StrFormatter;
import nckd.jxccl.hr.hstu.common.HonorStudentConstant;
import org.apache.commons.lang3.StringUtils;

/**
* 【优秀生】-综合测评答卷-提交评分校验
* @author W.Y.C
* @date 2025/8/4 11:29
* @version 1.0
*/
public class EvalResultPerfScoreValidate extends AbstractValidator {

    @Override
    public void initializeConfiguration() {
        //this.entityKey = HonorStudentConstant.NCKD_EVALRESULTENTRY;
    }

    @Override
    public void validate() {
        //处理分层级单据数据的标准工具（简单理解就是把层级的实体变为平铺）
        //RowDataModel rowDataModel = new RowDataModel(entityKey, getValidateContext().getBillEntityType());

        for (ExtendedDataEntity rowDataEntity : getDataEntities()) {

           /* rowDataModel.setRowContext(rowDataEntity.getDataEntity());
            Boolean unclear = ConvertUtil.toBoolean(rowDataModel.getValue(HonorStudentConstant.NCKD_UNCLEAR));*/
            DynamicObject dataEntity = rowDataEntity.getDataEntity();
            String perfPlanState = dataEntity.getString(HonorStudentConstant.NCKD_PERFPLANSTATE);
            if(!"1".equals(perfPlanState)){
                addErrorMessage(rowDataEntity, "只有问卷评分状态为【待评分】的问卷才能评分");
            }
            boolean unclear = dataEntity.getBoolean(HonorStudentConstant.NCKD_UNCLEAR);
            if(!unclear){
                DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection(HonorStudentConstant.NCKD_EVALRESULTENTRY);
                for (DynamicObject dynamicObject : dynamicObjectCollection) {
                    String perfScores = dynamicObject.getString(HonorStudentConstant.NCKD_PERFSCORES);
                    if(StringUtils.isBlank(perfScores)){
                        DynamicObject evalQuestTplEntry = dynamicObject.getDynamicObject(HonorStudentConstant.NCKD_EVALQUESTTPLENTRY);
                        String matter = evalQuestTplEntry.getString(HonorStudentConstant.NCKD_MATTER);
                        addErrorMessage(rowDataEntity, StrFormatter.format("评价内容【{}】没有评价分数，请评分后再提交", matter));
                    }
                }
            }
        }
    }
}