package com.yem.wm.es.salesorder.op;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.AttachmentServiceHelper;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.DeleteServiceHelper;

import java.util.List;
import java.util.Map;

/**
 * @author ljw
 * @date 2024/10/29 15:30
 * 删除国贸经理签批附件
 * @description SalesOrdDeleteattAchmentOp
 */
public class SalesOrdDeleteattAchmentOp extends AbstractOperationServicePlugIn {

    @Override
    public void endOperationTransaction(EndOperationTransactionArgs e) {
        super.endOperationTransaction(e);
        DynamicObject[] dataEntities = e.getDataEntities();
        for (DynamicObject dataEntitie : dataEntities) {
            dataEntitie = BusinessDataServiceHelper.loadSingle(dataEntitie.getPkValue(), dataEntitie.getDynamicObjectType().getName());
            createPdf(dataEntitie);
        }
    }

    private void createPdf(DynamicObject dataEntitie) {
        List<Map<String, Object>> salesorder = AttachmentServiceHelper.getAttachments(dataEntitie.getDynamicObjectType().getName(), dataEntitie.getLong("id"), "yem_approval");
        for (Map<String, Object> map : salesorder) {
            DeleteServiceHelper.delete("bos_attachment", new QFilter[]{new QFilter("id", QCP.equals, map.get("attPkId"))});
        }
    }
}