import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.jy.JyApplication;
import com.jy.business.config.RabbitMqUtil;
import com.jy.business.payment.dao.PaymentRequestsDao;
import com.jy.business.payment.model.entity.PaymentRequests;
import com.jy.framework.config.ObsConfig;
import jakarta.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = JyApplication.class)
@WebAppConfiguration
public class MySpringBootTest {

    @Resource
    private PaymentRequestsDao paymentRequestsDao;

    @Resource
    private ObsConfig obsConfig;

    @Test
    public void test2(){
        RabbitMqUtil.sendConfirmFundReceived(9999999L);
    }

    @Test
    public void test() {
        List<PaymentRequests> list = paymentRequestsDao.list(q -> q.isNotNull(PaymentRequests::getAtts));

        list.forEach(item -> {
            String atts = item.getAtts();
            List<JSONObject> javaList = JSONArray.parseArray(atts).toJavaList(JSONObject.class);

            javaList.forEach(i -> {
                String string = i.getString("url");
                String replace = string.replace("https://os.winfaster.cn/", getUrl());
                i.put("url", replace);
            });

            item.setAtts(JSONArray.toJSONString(javaList));
        });

        paymentRequestsDao.updateBatchById(list);

        System.out.println(list);
    }

    private String getUrl() {
        return "https://" + obsConfig.getBucketName() + "." + obsConfig.getEndPoint() + "/";
    }

}
