package com.hzs.bonus.risk.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.bonus.risk.mapper.CuMemberRiskControlMapper;
import com.hzs.bonus.risk.param.MemberRiskControlParam;
import com.hzs.bonus.risk.param.MemberRiskParam;
import com.hzs.bonus.risk.service.ICuMemberRiskControlService;
import com.hzs.bonus.risk.vo.MemberRiskControlVo;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.EApprovalBusiness;
import com.hzs.common.core.enums.EControlType;
import com.hzs.common.core.enums.ESignType;
import com.hzs.common.domain.activity.base.AcApprovalLog;
import com.hzs.common.domain.bonus.risk.CuMemberRiskControl;
import com.hzs.system.sys.dto.ApprovalSubmitDTO;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 会员奖金-K值风控设置 服务实现类
 * </p>
 *
 * @author zhangjing
 * @since 2024-04-08
 */
@Service
public class CuMemberRiskControlServiceImpl extends ServiceImpl<CuMemberRiskControlMapper, CuMemberRiskControl> implements ICuMemberRiskControlService {

    @Override
    public List<CuMemberRiskControl> queryCuMemberRiskControl(Date settleDate) {
        QueryWrapper<CuMemberRiskControl> queryWrapper = new QueryWrapper<>();
        queryWrapper.le("start_date", settleDate);
        queryWrapper.ge("end_date", settleDate);
        return baseMapper.selectList(queryWrapper);
    }
    /**
     * 列表查询
     * @param memberRiskControlParam
     * @return
     */
    @Override
    public List<MemberRiskControlVo> queryByList(MemberRiskControlParam memberRiskControlParam)
    {
        return baseMapper.queryByList(memberRiskControlParam);
    }

    /**
     * 添加审批
     * @param memberRiskParam
     */
    @Override
    public Boolean onLinePetition(MemberRiskParam memberRiskParam) {
        EApprovalBusiness approvalBusiness = null;
        if (memberRiskParam.getControlType() == EControlType.SAVE.getValue()){
            approvalBusiness = EApprovalBusiness.MEMBER_RISK_ADD;
        }else if (memberRiskParam.getControlType() == EControlType.MODIFY.getValue()){
            approvalBusiness = EApprovalBusiness.MEMBER_RISK_UPDATE;
        }else if (memberRiskParam.getControlType() == EControlType.DELETE.getValue()){
            approvalBusiness = EApprovalBusiness.MEMBER_RISK_REMOVE;
        }
        return submitApproval(memberRiskParam, approvalBusiness);
    }


    /**
     * 提交审批
     *
     * @param memberRiskParam 抽奖参数
     */
    public Boolean submitApproval(MemberRiskParam memberRiskParam, EApprovalBusiness approvalBusiness) {
        // TODO 审批未完成
//        //保存审批日志
//        AcApprovalLog approvalLog = saveApprovalLog(memberRiskParam, approvalBusiness);
//        ApprovalSubmitDTO approvalSubmitDTO = ApprovalSubmitDTO.builder().eApprovalBusiness(approvalBusiness)
//                .businessCode(approvalLog.getBusinessCode())
//                .businessData(JSONObject.toJSONString(memberRiskParam.getMemberRiskControlParam()))
//                .signType(ESignType.getEnumByValue(memberRiskParam.getSignType())).userIdList(memberRiskParam.getUserIdList())
//                .sendIdList(memberRiskParam.getSendIdList()).remark(memberRiskParam.getRemark()).fileList(memberRiskParam.getFileList())
//                .build();
//        R<String> submit = approvalServiceApi.submit(approvalSubmitDTO, memberRiskParam.getLoginUser());
//        if (!submit.isSuccess()) {
//            throw new RuntimeException("旅游活动参数提交审批失败！");
//        }
//        return submit.isSuccess();
        return null;
    }
}
