package com.yem.em.task;

import com.yem.em.utils.AtlasUtils;
import com.yem.wm.utils.RequestCmmp;
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.logging.Log;
import kd.bos.logging.LogFactory;
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.QueryServiceHelper;

import java.util.*;

import static com.yem.em.utils.AtlasUtils.seelctDyn;

/**
 * @author zhouc
 * @date 2023/12/2 17:53
 * @className BomChangeHisTaskEdit
 * @description BOM变更单历史数据获取定时任务
 */
public class BomChangeHisTaskEdit extends AbstractTask {
    public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
        Map<String, String> productmap = new HashMap<>();
        productmap.put("05", "L");//装载机
        productmap.put("002", "F");//叉车
        productmap.put("003", "T");//拖拉机
        QFilter qFilter = new QFilter("number", QCP.equals, "110");
        DynamicObject bos_org = BusinessDataServiceHelper.loadSingle("bos_org", "id", qFilter.toArray());
        String Queryfield = AtlasUtils.Queryfield("changebill_code", "pcode", "ccode", "qty", "break_flag", "enable_time", "disable_time", "state", "complete_time", "complete_user", "MATER_NAME", "CMATER_NAME", "COMPLETE_TIME");
        for (String key : productmap.keySet()) {
            String value = productmap.get(key);
            DynamicObject yem_bd_productsgroup = seelctDyn("yem_bd_productsgroup", "number", key);
            String sql = "select distinct " + Queryfield + "  from VIEW_CHANGEBILL_WM ";//where TO_CHAR (enable_time, 'yyyy-mm-dd') >= '2023-01-01'
            List<Map> fromCmmp = RequestCmmp.getFromCmmp(bos_org.getLong("id"), sql, yem_bd_productsgroup.getLong("id"));
            AtlasUtils.addbomchange(fromCmmp, value);
        }
    }
}
