package cn.iocoder.yudao.module.system.job;

import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.api.kingdee.KingdeeApi;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class KingdeeOrderBillSyncIdJob implements JobHandler {

    private final static Logger logger = LoggerFactory.getLogger(KingdeeOrderBillSyncIdJob.class);

    @Resource
    private KingdeeApi kingdeeApi;

    @Override
    @TenantIgnore
    public String execute(String jsonParam) {
        logger.info("kingdeeOrderBillSyncIdJob execute param:{}", jsonParam);
        Gson gson = new Gson();
        JsonObject jsonObject = gson.fromJson(jsonParam, JsonObject.class);
        JsonElement tenantIdElement = jsonObject.get("tenantId");
        if (tenantIdElement == null) {
            return "参数错误，tenantId为空！";
        }
        Long tenantId = tenantIdElement.getAsLong();
        // 收款单
//        Integer syncCount = kingdeeApi.syncArReceivebill(tenantId);
//        return String.format("租户{}同步金蝶用户账单数量{}", TenantContextHolder.getTenantId(), syncCount);
        return "";
    }

}
