package cn.pluss.platform.ys.impl.v20210929;

import cn.hutool.crypto.symmetric.DES;
import cn.jiguang.common.utils.StringUtils;
import cn.pluss.platform.IdCardService;
import cn.pluss.platform.SubMerchantApplyOrderService;
import cn.pluss.platform.channel.MerchantCertService;
import cn.pluss.platform.dto.AccountDTO;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.enums.WxApplyStatus;
import cn.pluss.platform.enums.WxAuthStatus;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.merchant.AccountService;
import cn.pluss.platform.merchant.MerchantBaseInfoService;
import cn.pluss.platform.merchantChannelStatus.MerchantChannelStatusService;
import cn.pluss.platform.merchantImage.MerchantImageService;
import cn.pluss.platform.notice.NoticeService;
import cn.pluss.platform.subMerchant.SubMerchantService;
import cn.pluss.platform.util.FileUtil;
import cn.pluss.platform.user.impl.GeneralPushUtil;
import cn.pluss.platform.util.OssOperatUtil;
import cn.pluss.platform.util.SendMsgUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;

/**
 * @author djh
 */
@Slf4j
@Service("ysCertV2Service")
public class YsCertServiceImpl implements MerchantCertService {

    @Autowired
    private MerchantBaseInfoService mbiService;

    @Autowired
    private MerchantChannelStatusService mcsService;

    @Autowired
    private MerchantImageService miService;

    @Autowired
    private SubMerchantApplyOrderService applyOrderService;

    @Autowired
    private YsServiceV2 ysService;

    @Autowired
    private YsConfigV2 ysConfigV2;

    @Autowired
    private AccountService accountService;

    @Autowired
    private IdCardService idCardService;

    @Autowired
    private SendMsgUtil sendMsgUtil;

    @Autowired
    private NoticeService noticeService;

    @Autowired
    private SubMerchantService smService;

    @Autowired
    private GeneralPushUtil generalPushUtil;


    /**
     * 826521754990231   测试商编
     *
     * @param merchantId   商户渠道编号
     * @param merchantCode 商户code
     */
    @Override
    public void wxCert(String merchantId, String merchantCode) {
        MerchantBaseInfo mbi = new MerchantBaseInfo();
        mbi.setMerchantCode(merchantCode);
        mbi = mbiService.getOne(new QueryWrapper<>(mbi));

        MerchantImage merImg = new MerchantImage();
        merImg.setMerchantCode(merchantCode);
        merImg.setPhotoType(MerchantImage.ImageType.SHOP_FRONT_DOOR);
        merImg = miService.getOne(Wrappers.query(merImg));

        MerchantImage merImg2 = new MerchantImage();
        merImg2.setMerchantCode(merchantCode);
        merImg2.setPhotoType(MerchantImage.ImageType.STORE_INTERIOR_PHOTO);
        merImg2 = miService.getOne(Wrappers.query(merImg2));

        AccountDTO account = accountService.getAccount(mbi.getUserId());

        String token;
        try {
            JSONObject tokenJson = getToken();
            JSONObject bizContent = tokenJson.getJSONObject("ysepay_merchant_register_token_get_response");
            token = bizContent.getString("token");
        } catch (Exception e) {
            log.error("银盛微信认证获取token失败!");
            return;
        }

        if ("1".equals(mbi.getMerchantType())) {
            // 小微商户需要上传图片
            uploadImg(token, merchantId, merImg);
            uploadImg(token, merchantId, merImg2);
        }

        /*
         * {
         *     "sign": "CjoulHUit4wig8AyImfSb58ttsQS2cwZNKM/6fTot5rDmUfL730veMWh2Li8HLda5KlPamyF5WbFhGisDjyiSgsZ4Ls0XO45rZAEYmAXVnSjOyAqNS8CgYZ3vSZg3jFl5vuRvrHr4vdPxTKQ/xW9K1D+fJOnMi90+K+9mXmDrPI=",
         *     "ysepay_authenticate_wx_apply_response": {
         *     "code": "10000",
         *     "msg": "Success",
         *     "apply_no": "2000002223643720",
         *     "send_channel_apply_no": "R1028184853490168051"
         * }
         */
        JSONObject reqResult = wxCertReq(token, merchantId, mbi, account);
        JSONObject wxCertResult = reqResult.getJSONObject("ysepay_authenticate_wx_apply_response");

        if ("Success".equals(wxCertResult.getString("msg"))) {
            String applyNo = wxCertResult.getString("apply_no");

            // 将之前微信认证请求发生错误的信息直接全部清理
            LambdaQueryWrapper<SubMerchantApplyOrder> qWrapper = Wrappers.lambdaQuery();
            qWrapper.eq(SubMerchantApplyOrder::getMerchantCode, merchantCode)
                    .eq(SubMerchantApplyOrder::getChannelId, 4);

            applyOrderService.remove(qWrapper);

            SubMerchantApplyOrder subMerchantApplyOrder = new SubMerchantApplyOrder()
                    .setMerchantCode(mbi.getMerchantCode())
                    .setSubMchType("WX")
                    .setStatus("0")
                    .setApplyNo(applyNo)
                    .setChannelId(4);

            applyOrderService.save(subMerchantApplyOrder);
        } else {
            log.error("商户微信认证异常{}", wxCertResult);

            String msg = "微信认证异常";
            SubMerchantApplyOrder subMerchantApplyOrder = new SubMerchantApplyOrder()
                    .setMerchantCode(mbi.getMerchantCode())
                    .setSubMchType("WX")
                    .setStatus("0")
                    .setRemark(msg)
                    .setResultStatus(SubMerchantApplyOrder.RES_STATUS_COMMIT_ERROR)
                    .setChannelId(4);

            // 先更新
            LambdaUpdateWrapper<SubMerchantApplyOrder> uWrapper = Wrappers.lambdaUpdate();
            uWrapper.eq(SubMerchantApplyOrder::getMerchantCode, merchantCode);
            uWrapper.eq(SubMerchantApplyOrder::getChannelId, 4);
            uWrapper.eq(SubMerchantApplyOrder::getResultStatus, "4");
            uWrapper.set(SubMerchantApplyOrder::getStatus, "0")
                    .set(SubMerchantApplyOrder::getResultStatus, SubMerchantApplyOrder.RES_STATUS_COMMIT_ERROR)
                    .set(SubMerchantApplyOrder::getRemark, msg)
                    .set(SubMerchantApplyOrder::getUpdateTime, new Date());
            boolean updateFlag = applyOrderService.update(uWrapper);
            if (!updateFlag) {
                applyOrderService.save(subMerchantApplyOrder);
            }
        }
    }

    @Override
    public void wxReCert(String merchantId, String merchantCode) {
        SubMerchantApplyOrder subMerchantApplyOrder = new SubMerchantApplyOrder()
                .setMerchantCode(merchantCode)
                .setStatus("1")
                .setChannelId(4);
        subMerchantApplyOrder = applyOrderService.getOne(new QueryWrapper<>(subMerchantApplyOrder));

        wxCertCancel(merchantId, subMerchantApplyOrder);

        wxCert(merchantId, merchantCode);
    }

    @Override
    public JSONObject wxCertResult(String merchantId, String wxApplyNo) {
        JSONObject param = new JSONObject();
        param.put("apply_no", wxApplyNo);

        JSONObject reqResult = ysService.req(YsConfigV2.MER_WX_CERT, "ysepay.authenticate.wx.query", param, null);
        JSONObject wxCertResult = reqResult.getJSONObject("ysepay_authenticate_wx_query_response");
        if (!"10000".equals(wxCertResult.getString("code"))) {
            log.error("微信申请单{}, 查询状态失败, {}", wxApplyNo, wxCertResult.getString("msg"));
            return null;
        }

        String applyState = wxCertResult.getString("apply_state");
        String qrcodeData = wxCertResult.getString("qrcode_data");
        if (applyState.equals(WxApplyStatus.EXAMINING.getStatusName())) {
            LambdaUpdateWrapper<SubMerchantApplyOrder> uWrapper = Wrappers.lambdaUpdate();
            uWrapper.eq(SubMerchantApplyOrder::getApplyNo, wxApplyNo);
            uWrapper.set(SubMerchantApplyOrder::getResultStatus, applyState)
                    .set(SubMerchantApplyOrder::getUpdateTime, new Date())
                    .set(SubMerchantApplyOrder::getRemark, WxApplyStatus.EXAMINING.getStatusMsg())
                    .set(SubMerchantApplyOrder::getStatus, "0");
            applyOrderService.update(uWrapper);

        } else if (applyState.equals(WxApplyStatus.EDITING.getStatusName())) {
            LambdaUpdateWrapper<SubMerchantApplyOrder> uWrapper = Wrappers.lambdaUpdate();
            uWrapper.eq(SubMerchantApplyOrder::getApplyNo, wxApplyNo);
            uWrapper.set(SubMerchantApplyOrder::getResultStatus, applyState)
                    .set(SubMerchantApplyOrder::getUpdateTime, new Date())
                    .set(SubMerchantApplyOrder::getRemark, WxApplyStatus.EDITING.getStatusMsg())
                    .set(SubMerchantApplyOrder::getStatus, "0");
            applyOrderService.update(uWrapper);

        } else if (applyState.equals(WxApplyStatus.CONFIRM_CONTACT.getStatusName())) {
            success(merchantId, wxApplyNo, qrcodeData, WxApplyStatus.CONFIRM_CONTACT);

        } else if (applyState.equals(WxApplyStatus.CONFIRM_LEGALPERSON.getStatusName())) {
            success(merchantId, wxApplyNo, qrcodeData, WxApplyStatus.CONFIRM_LEGALPERSON);

        } else if (applyState.equals(WxApplyStatus.PASSED.getStatusName())) {
            success(merchantId, wxApplyNo, qrcodeData, WxApplyStatus.PASSED);

        } else if (applyState.equals(WxApplyStatus.REJECTED.getStatusName())) {
            LambdaUpdateWrapper<SubMerchantApplyOrder> uWrapper = Wrappers.lambdaUpdate();
            uWrapper.eq(SubMerchantApplyOrder::getApplyNo, wxApplyNo);
            uWrapper.set(SubMerchantApplyOrder::getResultStatus, applyState)
                    .set(SubMerchantApplyOrder::getUpdateTime, new Date())
                    .set(SubMerchantApplyOrder::getRemark, WxApplyStatus.EDITING.getStatusMsg())
                    .set(SubMerchantApplyOrder::getStatus, "0");
            applyOrderService.update(uWrapper);

            try {
                MerchantChannelStatus mcs = new MerchantChannelStatus();
                mcs.setChannel(4);
                mcs.setMerchantId(merchantId);
                mcs = mcsService.getOne(Wrappers.query(mcs));

                MerchantBaseInfo mbi = mbiService.getMerchantBaseInfoByMerchantCode(mcs.getMerchantCode());

                String pushMsg = "您好！您的商户微信认证因“##”被驳回，请联系收银呗客服修改资料并重新审核";
                pushMsg = pushMsg.replace("##", wxCertResult.getString("reject_reason"));
                generalPushUtil.sendAllPlatByAlias(Collections.singletonList(mbi.getUserId()), "商户微信认证通知", pushMsg, "1");

                Notice notice = new Notice(1, 1, mbi.getUserId());
                notice.setConrtent(pushMsg);
                noticeService.saveNotice(notice);
            } catch (MsgException e) {
                log.error(e.getMessage());
            }

        } else if (applyState.equals(WxApplyStatus.FREEZED.getStatusName())) {
            success(merchantId, wxApplyNo, qrcodeData, WxApplyStatus.FREEZED);

        } else if (applyState.equals(WxApplyStatus.CANCELED.getStatusName())) {
            LambdaUpdateWrapper<SubMerchantApplyOrder> uWrapper = Wrappers.lambdaUpdate();
            uWrapper.eq(SubMerchantApplyOrder::getApplyNo, wxApplyNo);
            uWrapper.set(SubMerchantApplyOrder::getResultStatus, WxApplyStatus.CANCELED.getStatusName())
                    .set(SubMerchantApplyOrder::getUpdateTime, new Date())
                    .set(SubMerchantApplyOrder::getRemark, WxApplyStatus.CANCELED.getStatusMsg())
                    .set(SubMerchantApplyOrder::getStatus, "2");
            applyOrderService.update(uWrapper);
        }

        return null;
    }

    /**
     * 有小程序码返回的
     */
    private void success(String merchantId, String wxApplyNo, String qrcodeData, WxApplyStatus wxApplyStatus) {
        LambdaUpdateWrapper<SubMerchantApplyOrder> uWrapper = Wrappers.lambdaUpdate();
        uWrapper.eq(SubMerchantApplyOrder::getApplyNo, wxApplyNo);
        uWrapper.set(SubMerchantApplyOrder::getResultStatus, wxApplyStatus.getStatusName())
                .set(SubMerchantApplyOrder::getUpdateTime, new Date())
                .set(SubMerchantApplyOrder::getRemark, wxApplyStatus.getStatusMsg())
                .set(SubMerchantApplyOrder::getStatus, "1");
        uWrapper.set(SubMerchantApplyOrder::getInfoQrcode, uploadOSS(qrcodeData));
        applyOrderService.update(uWrapper);

        notify(merchantId);
    }

    /**
     * 上传认证二维码图片信息到OSS
     * @param base64ImgData 图片base64编码信息
     * @return  OSS图片链接
     */
    private String uploadOSS(String base64ImgData) {
        base64ImgData = base64ImgData.replace("data:image/png;base64,", "");

        byte[] decode = Base64.getDecoder().decode(base64ImgData);
        ByteArrayInputStream bais = new ByteArrayInputStream(decode);
        return OssOperatUtil.upload(bais, UUID.randomUUID().toString(), "png");
    }

    /**
     * 给商户发推送以及短信
     * @param merchantId    通道商编
     */
    private void notify(String merchantId) {
        try {
            MerchantChannelStatus mcs = new MerchantChannelStatus();
            mcs.setChannel(4);
            mcs.setMerchantId(merchantId);
            mcs = mcsService.getOne(Wrappers.query(mcs));

            MerchantBaseInfo mbi = mbiService.getMerchantBaseInfoByMerchantCode(mcs.getMerchantCode());

            String content = "请商户进行微信实名认证，短信将发送至商户联系人手机号，已认证可忽略";
            generalPushUtil.sendAllPlatByAlias(Collections.singletonList(mbi.getUserId()), "商户微信认证通知", content, "1");

            sendMsgUtil.verifyMsg(mbi.getContactMobile(), mbi.getMerchantCode() + "?i=" + 4);

            Notice notice = new Notice(1, 1, mbi.getUserId());
            notice.setConrtent(content);
            noticeService.saveNotice(notice);
        } catch (MsgException e) {
            log.error(e.getMessage());
        }
    }

    /**
     * 获取token
     *
     * @return 返回参数
     * {
     * "ysepay_merchant_register_token_get_response": {
     * "msg": "Success",
     * "token_status": "TOKEN_GET_SUCCESS",
     * "code": "10000",
     * "token": "TK20211028151009850PQoPfeku"
     * },
     * "sign": "DU3+iNNNOHiMjDRlMf34ubE6Eqxtegj3b5HXhxjhWnS/WG+NX+QoTSLIV0Zm6Z8rP9/51N4OYUQTRhVpAbVD8Ub8J4fIv7cNpb7fd9SnO6XwOEq9YlJK6Plpk3W0lWq9sD/UJDEvG2Ab1zV+EJ9C7htFbJLrTNPkuIoQ4bQterY="
     * }
     * @throws Exception 可能存在的异常信息
     */
    public JSONObject getToken() throws Exception {
        Map<String, Object> extraBase = new HashMap<>();
        extraBase.put("notify_url", "http://api.test.ysepay.net/atinterface/receive_return.htm");
        JSONObject bizContent = new JSONObject();
        bizContent.put("biz_content", "{}");
        JSONObject tokenResult = ysService.req(YsConfigV2.MER_UPLOAD_TOKEN, "ysepay.merchant.register.token.get", new JSONObject(), extraBase);

        return tokenResult;
    }

    /**
     * 上传图片
     *
     * @param token      token
     * @param merchantId 商编
     * @param mi         图片信息
     */
    private void uploadImg(String token, String merchantId, MerchantImage mi) {
        String picType;
        if (mi.getPhotoType().equals(MerchantImage.ImageType.SHOP_FRONT_DOOR)) {
            picType = "34";
        } else if (mi.getPhotoType().equals(MerchantImage.ImageType.STORE_INTERIOR_PHOTO)) {
            picType = "50";
        } else {
            return;
        }

        JSONObject bizParam = new JSONObject();
        bizParam.put("superUsercode", merchantId);
        bizParam.put("picType", picType);
        bizParam.put("token", token);

        Map<String, Object> fileMap = new HashMap<>();
        try {
            byte[] base64 = FileUtil.url2Bytes(mi.getPicUrl());
            ByteArrayResource file = new ByteArrayResource(base64) {
                @Override
                public String getFilename() {
                    return "test.jpg";
                }
            };
            fileMap.put("picFile", file);
        } catch (IOException ignored) {

        }

        JSONObject uploadResult = ysService.req(YsConfigV2.MER_IMG_UPLOAD, null, null, bizParam, fileMap);
        log.debug("银盛微信认证上传图片返回结果：{}", uploadResult.toJSONString());
    }

    /**
     * 发起微信认证
     *
     * @return 发起微信认证的结果
     * {
     * "sign": "CjoulHUit4wig8AyImfSb58ttsQS2cwZNKM/6fTot5rDmUfL730veMWh2Li8HLda5KlPamyF5WbFhGisDjyiSgsZ4Ls0XO45rZAEYmAXVnSjOyAqNS8CgYZ3vSZg3jFl5vuRvrHr4vdPxTKQ/xW9K1D+fJOnMi90+K+9mXmDrPI=",
     * "ysepay_authenticate_wx_apply_response": {
     * "code": "10000",
     * "msg": "Success",
     * "apply_no": "2000002223643720",
     * "send_channel_apply_no": "R1028184853490168051"
     * }
     * }
     */
    private JSONObject wxCertReq(String token, String merchantId, MerchantBaseInfo mbi, AccountDTO account) {

        JSONObject bizContent = new JSONObject();
        bizContent.put("usercode", merchantId);
        if ("1".equals(mbi.getMerchantType())) {
            IdCard idCard = account.getIdcard();
            bizContent.put("cust_name", "商户_" + idCard.getCertName());
        } else {
            String bizName = mbi.getBussAuthName();

            if (StringUtils.isNotEmpty(bizName) && !"**".equals(bizName)) {
                bizContent.put("cust_name", bizName);
            } else {
                // 获取法人信息
                IdCard legalIdCard = idCardService.getLegalIdCard(mbi.getUserId());
                bizContent.put("cust_name", "个体户_" + legalIdCard.getCertName());
            }
        }

        bizContent.put("contact_cert_type", "00");
        DES des = new DES(ysConfigV2.getSrcMerchantNo().getBytes(StandardCharsets.UTF_8));

        bizContent.put("contact_cert_no", des.encryptBase64(account.getIdcard().getCertNo()));
        bizContent.put("legal_cert_initial", account.getIdcard().getCertStartTime().replace("-", ""));
        if ("长期".equals(account.getIdcard().getCertEndTime())) {
            bizContent.put("legal_cert_expire", "29991231");
        } else {
            bizContent.put("legal_cert_expire", account.getIdcard().getCertEndTime().replace("-", ""));
        }

        if (!"1".equals(mbi.getMerchantType())) {
            bizContent.put("bus_license_initial", mbi.getBussAuthStartTime().replace("-", ""));
            bizContent.put("bus_license_expire", mbi.getBussAuthEndTime().replace("-", ""));
        } else {
            bizContent.put("store_type", "00");
            bizContent.put("store_name", mbi.getAlias());
            bizContent.put("token", token);
        }

        JSONObject merContactInfo = new JSONObject();
        merContactInfo.put("mer_contact_type", "65");
        merContactInfo.put("id_type_cd", "00");

        merContactInfo.put("id_validdate_begin", account.getIdcard().getCertStartTime());
        merContactInfo.put("id_validdate_end", account.getIdcard().getCertEndTime());
        bizContent.put("mer_contact_info", merContactInfo);


        JSONObject wxCertResult = ysService.req(YsConfigV2.MER_WX_CERT, "ysepay.authenticate.wx.apply", bizContent, null);
        log.debug("银盛微信认证请求返回结果：{}", wxCertResult.toString());

        return wxCertResult;
    }

    @Override
    public JSONObject wxCertCallback(JSONObject certResult) {
        // 银盛没有回调
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void wxCertCancel(String merchantId, SubMerchantApplyOrder subMerchantApplyOrder) {
        JSONObject paramMap = new JSONObject();
        paramMap.put("apply_no", subMerchantApplyOrder.getApplyNo());

        JSONObject reqResult = ysService.req(YsConfigV2.MER_WX_CERT, "ysepay.authenticate.wx.apply.cancel", paramMap, null);
        JSONObject respResult = reqResult.getJSONObject("ysepay_authenticate_wx_apply_cancel_response");

        if (!"00".equals(respResult.getString("apply_state"))) {
            throw new MsgException(respResult.getString("sub_msg"));
        }
    }

    @Override
    public void wxCertAuthStatus(String merchantId) {
        JSONObject bizContent = new JSONObject();
        bizContent.put("usercode", merchantId);

        JSONObject reqResult = ysService.req(YsConfigV2.MER_WX_CERT, "ysepay.authenticate.wx.authorized.query", bizContent, null);
        JSONObject respResult = reqResult.getJSONObject("ysepay_authenticate_wx_authorized_query_response");
        String thirdAuthStatusX = respResult.getString("thirdparty_authstate_x");
        String thirdMercIdX = respResult.getString("thirdparty_mercid_x");
        String thirdAuthStatusY = respResult.getString("thirdparty_authstate_y");
        String thirdMercIdY = respResult.getString("thirdparty_mercid_y");

        LambdaQueryWrapper<SubMerchant> qWrapper = Wrappers.lambdaQuery();
        qWrapper.eq(SubMerchant::getMerchantId, merchantId);
        qWrapper.likeLeft(SubMerchant::getSubMchId, "_CUPS");
        qWrapper.eq(SubMerchant::getSubMchType, "WX");
        SubMerchant sub = smService.getOne(qWrapper);

        if (sub == null) {
            MerchantChannelStatus mcs = new MerchantChannelStatus().setMerchantId(merchantId).setChannel(4);
            mcs = mcsService.getOne(new QueryWrapper<>(mcs));
            smService.reqChannelSubMerchant(mcs.getMerchantCode(), mcs.getChannel());
            sub = smService.getOne(qWrapper);
            if (sub == null) {
                log.warn("未查询到银联微信子商户号");
                return;
            }
        }

        String wxMercId = sub.getSubMchId().split("_")[0];
        if (Objects.equals(thirdAuthStatusX, WxAuthStatus.AUTHORIZED.getName()) && wxMercId.equals(thirdMercIdX)) {
            LambdaUpdateWrapper<MerchantChannelStatus> uWrapper = Wrappers.lambdaUpdate();
            uWrapper.eq(MerchantChannelStatus::getMerchantId, merchantId);
            uWrapper.eq(MerchantChannelStatus::getChannel, 4);
            uWrapper.set(MerchantChannelStatus::getAuthorizationStatus, MerchantChannelStatus.AUTHORIZATION_STATUS_AUTHORIZED);
            mcsService.update(uWrapper);
            return;
        }


        if (Objects.equals(thirdAuthStatusY, WxAuthStatus.AUTHORIZED.getName()) && wxMercId.equals(thirdMercIdY)) {
            LambdaUpdateWrapper<MerchantChannelStatus> uWrapper = Wrappers.lambdaUpdate();
            uWrapper.eq(MerchantChannelStatus::getMerchantId, merchantId);
            uWrapper.eq(MerchantChannelStatus::getChannel, 4);
            uWrapper.set(MerchantChannelStatus::getAuthorizationStatus, MerchantChannelStatus.AUTHORIZATION_STATUS_AUTHORIZED);
            mcsService.update(uWrapper);
        }
    }
}
