package com.yem.wm.es.storagetrans.task;

import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.exception.KDException;
import kd.bos.orm.query.QFilter;
import kd.bos.schedule.executor.AbstractTask;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;

import java.util.Map;

/**
 * @Description: 订舱通知单 是否报关为是的   单证审核 都更新成张素玉
 * @Date: 2024/7/19 15:06
 * @Created: by ZZSLL
 */

public class StorageTransDataFixTask extends AbstractTask {
    @Override
    public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
        DynamicObject[] load = BusinessDataServiceHelper.load("yem_es_storagetrans", "id, billno, yem_docreview, yem_isdeclare",
                new QFilter[]{new QFilter("billstatus", "=", "C"),
                        new QFilter("yem_isdeclare", "=", "A")});

        DynamicObject user = BusinessDataServiceHelper.loadSingle("bos_user", new QFilter[]{new QFilter("phone", "=", "15063663477")});
        if (user == null) {return;}
        for (DynamicObject single : load) {
            DynamicObjectCollection docreview = single.getDynamicObjectCollection("yem_docreview");
            docreview.clear();
            DynamicObject newObj = new DynamicObject(docreview.getDynamicObjectType());
            newObj.set("fbasedataid", user);
            docreview.add(newObj);
            single.set("yem_docreview", docreview);
        }
        SaveServiceHelper.save(load);
    }
}
