package com.hzs.member.base.provider;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.constant.EnumsPrefixConstants;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.EPopupType;
import com.hzs.common.core.enums.EnableStatus;
import com.hzs.common.domain.member.detail.CuMemberServiceLog;
import com.hzs.common.service.ITransactionCommonService;
import com.hzs.member.base.IUpPolicyCurrencyServiceApi;
import com.hzs.member.base.dto.UpPolicyCurrencyDTO;
import com.hzs.member.detail.service.ICuMemberServiceLogService;
import com.hzs.member.handlebusiness.dto.AnalysisBusinessAppealParam;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

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

/**
 * 修改政策币涉及dubbo服务
 */
@DubboService
public class UpPolicyCurrencyServiceProvider implements IUpPolicyCurrencyServiceApi {

    @Autowired
    private ICuMemberServiceLogService memberServiceLogService;
    @Autowired
    private ITransactionCommonService iTransactionCommonService;

    @Override
    public R<List<UpPolicyCurrencyDTO>> policyCurrencyList(AnalysisBusinessAppealParam analysisBusinessAppealParam) {
        List<UpPolicyCurrencyDTO> list = new ArrayList<>();
        CuMemberServiceLog memberServiceLog = new CuMemberServiceLog();
        memberServiceLog.setBusinessNo(analysisBusinessAppealParam.getBusinessNo());
        QueryWrapper<CuMemberServiceLog> queryWrapper = new QueryWrapper();
        queryWrapper.eq("BUSINESS_NO", analysisBusinessAppealParam.getBusinessNo());
        Map<String, String> transactionMap = iTransactionCommonService.exportEnumTransaction(EnableStatus.values(), EPopupType.values());
        List<CuMemberServiceLog> msList = memberServiceLogService.list(queryWrapper);
        if (CollectionUtil.isNotEmpty(msList)) {
            msList.forEach(item -> {
                UpPolicyCurrencyDTO upc = JSONObject.parseObject(item.getNewValue(), UpPolicyCurrencyDTO.class);
                upc.setEnableStatusVal(transactionMap.get(EnumsPrefixConstants.ENABLE_STATUS + upc.getEnableStatus()));
                upc.setTransferVal(transactionMap.get(EnumsPrefixConstants.POPUP_TYPE + upc.getTransfer()));
                list.add(upc);
            });
        }
        return R.ok(list);
    }
}
