package com.cpop.oam.web;

import com.alibaba.fastjson.JSONObject;
import com.cpop.api.tencent.location.handler.TencentLocationHandler;
import com.cpop.core.base.entity.LoginUser;
import com.cpop.core.utils.SecurityUtils;
import com.cpop.core.utils.SpringUtils;
import com.cpop.jambox.business.entity.StoreExtend;
import com.cpop.jambox.business.service.StoreExtendService;
import com.cpop.oam.business.entity.Clue;
import com.cpop.oam.business.service.ClueService;
import com.cpop.system.business.entity.Store;
import com.cpop.system.business.service.StoreService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.Db;
import com.mybatisflex.core.row.Row;
import com.mybatisflex.core.row.RowKey;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

import static com.cpop.jambox.business.entity.table.StoreExtendTableDef.STORE_EXTEND;
import static com.cpop.system.business.entity.table.StoreTableDef.STORE;

/**
 * @author DB
 * @version 1.0.0
 * @since 2024-02-21 14:44
 */
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class CpopClueTests {

    @Test
    public void insertClue() {
        LocalDateTime now = LocalDateTime.now();
        //添加线索以及
        Row clue = Row.ofKey(RowKey.SNOW_FLAKE_ID);
        clue.set("store_id","81892317270687744");
        //校区城市
        JSONObject geocoder = SpringUtils.getBean(TencentLocationHandler.class).geocoder("113.93041", "22.53332", "UGLBZ-LBF3I-ETCGO-UUH5X-QDV45-3LFKA");
        if (geocoder.getInteger("status") == 0){
            clue.set("city",geocoder.getJSONObject("result").getJSONObject("ad_info").getString("city"));
        }
        clue.set("clue_status",0);
        clue.set("create_time", now);
        clue.set("update_time", now);
        LoginUser loginUser = SecurityUtils.getInstance().getLoginUser();
        clue.set("create_user_id", loginUser == null ? "1" : loginUser.getUserId());
        clue.set("update_user_id", loginUser == null ? "1" : loginUser.getUserId());
        Db.insert("cp_oam_clue",clue);
        //录入记录
        Row clueRecord = Row.ofKey(RowKey.SNOW_FLAKE_ID);
        clueRecord.set("clue_id",clue.getString("id"));
        clueRecord.set("record_type",0);
        clueRecord.set("record_content", "机构负责人" + "测试" + "创建线索");
        clueRecord.set("record_staff_id", "1");
        clueRecord.set("create_time", now);
        clueRecord.set("update_time", now);
        clueRecord.set("create_user_id", loginUser == null ? "1" : loginUser.getUserId());
        clueRecord.set("update_user_id", loginUser == null ? "1" : loginUser.getUserId());
        Db.insert("cp_oam_clue_record",clueRecord);
    }


}
