package com.yem.wm.task;

import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.exception.KDException;
import kd.bos.orm.query.QCP;
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;

public class UpdateDBTask extends AbstractTask {
    @Override
    public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
        DynamicObject[] yem_bd_mechanicals = BusinessDataServiceHelper.load("yem_bd_mechanical", "id",
                new QFilter[]{new QFilter("status",QCP.equals,"C").and(
                new QFilter("enable",QCP.equals,"1"))});
        for (DynamicObject yemBdMechanical : yem_bd_mechanicals) {
            yemBdMechanical = BusinessDataServiceHelper.loadSingle(yemBdMechanical.getLong("id"),"yem_bd_mechanical");
            String fullname = yemBdMechanical.getDynamicObject("yem_bd_products").getDynamicObject("group").getString("fullname");
            yemBdMechanical.set("yem_productsgrouptxt",fullname);
            SaveServiceHelper.update(yemBdMechanical);
        }
    }
}
