package com.ruoyi.system.service.impl.Conversion;

import com.ruoyi.system.domain.ActHistoryRoleTypeCodeModel;
import com.ruoyi.system.domain.ActReadHistoryModel;
import com.ruoyi.system.mapper.ActReadDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;

/**
 * 2024/3/27
 */
@Service
public class MineConver {
    /*private MineConversion mineConversion;

    public MineConver(MineConversion mineConversion) {
        this.mineConversion = mineConversion;
    }*/

    @Autowired
    private OtherMethod otherMethod;

    private void setOtherMethod(OtherMethod otherMethod) {
        this.otherMethod = otherMethod;
    }
    @Autowired
    private LkSpecialMethod lkSpecialMethod;

    private void setLkSpecialMethod(LkSpecialMethod lkSpecialMethod) {
        this.lkSpecialMethod = lkSpecialMethod;
    }

    @Autowired
    private ActReadDataMapper actReadDataMapper;

    private static final String LK = "011702";

    //@Async注解，注意：如果调用方法和被调用方法都在Service中，则不生效
    @Async("defaultThreadPoolExecutor")
    //public void readToId(String mineId) {
    public Future<String> readToId(String mineId, int i) {

        // 模拟耗时操作
        try {
            Map<String, String> materialMap = new HashMap<>();
            List<ActHistoryRoleTypeCodeModel> listMaterial = actReadDataMapper.selectMaterialCode();
            for (ActHistoryRoleTypeCodeModel model : listMaterial) {
                materialMap.putIfAbsent(model.getKey(), model.getValue());
            }
            List<ActReadHistoryModel> list = actReadDataMapper.readDateToHistory(mineId, 1);
            ActReadHistoryModel historyModel = list.get(0);
            if (mineId.equals(LK)) {
                LkSpecialMethod lkSpecialMethod = new LkSpecialMethod(actReadDataMapper);
                //调用清洗方法
                lkSpecialMethod.conversion(historyModel, materialMap);
            } else {
                OtherMethod otherMethod = new OtherMethod(actReadDataMapper);
                //调用清洗方法
                otherMethod.conversion(historyModel, materialMap);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new AsyncResult<>("YES");


    }

    /*public void clean(ActReadHistoryModel actReadHistoryModel, Object obj){
        mineConversion.conversion(actReadHistoryModel, obj);
    }*/
}
