package com.mortals.xhx.busiz;

import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.PhoneUtil;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.PageInfo;
import com.mortals.xhx.base.framework.config.InterceptorConfig;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.busiz.baseinfo.BaseInfoDetail;
import com.mortals.xhx.busiz.baseinfo.BaseInfoReq;
import com.mortals.xhx.busiz.login.DatumDataReq;
import com.mortals.xhx.busiz.matters.MattersInfo;
import com.mortals.xhx.busiz.matters.MyMattersReq;
import com.mortals.xhx.busiz.oneProblemlist.OneProblemInfo;
import com.mortals.xhx.busiz.oneProblemlist.OneProblemReq;
import com.mortals.xhx.busiz.onethinglist.OneThineInfo;
import com.mortals.xhx.busiz.onethinglist.OneThingReq;
import com.mortals.xhx.busiz.question.QuestionInfo;
import com.mortals.xhx.busiz.question.QuestionReq;
import com.mortals.xhx.busiz.uploadfile.DeleteFileReq;
import com.mortals.xhx.busiz.uploadfile.UploadDatumReq;
import com.mortals.xhx.busiz.wechat.WechatBaseReq;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
import com.mortals.xhx.common.code.ApproveStateEnum;
import com.mortals.xhx.common.code.OneThingRespCodeEnum;
import com.mortals.xhx.common.code.OneThingTypeEnum;
import com.mortals.xhx.common.keys.BusizParams;
import com.mortals.xhx.feign.flowable.IApiFlowInstanceFeign;
import com.mortals.xhx.feign.rsp.ApiResp;
import com.mortals.xhx.feign.runtime.StartProcessInstanceReq;
import com.mortals.xhx.module.basics.model.BasicsDatumEntity;
import com.mortals.xhx.module.basics.model.BasicsDatumQuery;
import com.mortals.xhx.module.basics.model.BasicsEntity;
import com.mortals.xhx.module.basics.model.BasicsQuery;
import com.mortals.xhx.module.basics.service.BasicsDatumService;
import com.mortals.xhx.module.basics.service.BasicsService;
import com.mortals.xhx.module.classify.service.ClassifyOptionService;
import com.mortals.xhx.module.classify.service.ClassifyService;
import com.mortals.xhx.module.datum.service.DatumFileService;
import com.mortals.xhx.module.member.model.MemberEntity;
import com.mortals.xhx.module.member.model.MemberQuery;
import com.mortals.xhx.module.member.service.MemberService;
import com.mortals.xhx.module.yth.service.YthOnethingService;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 微信认证
 *
 * @author: zxfei
 * @date: 2021/8/24 20:28
 */
@RestController
@CommonsLog
@RequestMapping("/zwfw/wechatinter/")
public class WxWechatApiController {

    @Autowired
    private MemberService memberService;
    @Autowired
    private InterceptorConfig config;
    @Autowired
    private UploadService uploadService;
    @Autowired
    private DatumFileService datumFileService;


    /**
     * 微信注册认证
     *
     * @param req
     * @return
     */
    @PostMapping("base/checkCard")
    public ApiResp<String> wxCheckCard(WechatBaseReq req) {
        ApiResp<String> rsp = new ApiResp<>();
        rsp.setMsg(OneThingRespCodeEnum.SUCCESS.getLabel());
        rsp.setCode(OneThingRespCodeEnum.SUCCESS.getValue());
        try {

            //校验部分参数
            if (!PhoneUtil.isPhone(req.getTel())) {
                rsp.setMsg("电话号码不正确！");
                rsp.setCode(OneThingRespCodeEnum.FAILED.getValue());
                return rsp;
            }

            if (!IdcardUtil.isValidCard(req.getIdcard())) {
                rsp.setMsg("身份证号码不正确！");
                rsp.setCode(OneThingRespCodeEnum.FAILED.getValue());
                return rsp;
            }

            memberService.checkMember(req);


        } catch (Exception e) {
            log.error("微信注册认证失败", e);
            rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
            rsp.setMsg(e.getMessage());
            return rsp;
        }

        log.info("响应【微信注册认证】【响应体】-->  " + JSONObject.toJSONString(rsp));
        return rsp;
    }


}
