package com.cirle.scientific.controller.user;


import com.cirle.scientific.constants.SaveYsAndSmConsts;
import com.cirle.scientific.constants.TaskConsts;
import com.cirle.scientific.dao.MemberDao;
import com.cirle.scientific.dao.QkjMemberTaskInfoDao;
import com.cirle.scientific.dto.QkjMemberDto;
import com.cirle.scientific.po.QkjMember;
import com.cirle.scientific.pojo.BizCodeEnum;
import com.cirle.scientific.pojo.Result;
import com.cirle.scientific.service.MemberService;
import com.cirle.scientific.service.MemberTaskInfoService;
import com.cirle.scientific.service.QkjTaskService;
import com.cirle.scientific.service.UserService;
import com.cirle.scientific.utils.IpUtil;
import com.cirle.scientific.utils.OSSUtils;
import com.cirle.scientific.utils.UUID;
import com.cirle.scientific.utils.UserLoginUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileNotFoundException;
import java.text.ParseException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Controller
@RequestMapping("/user")
@Api("个人中心相关接口")
@Slf4j
public class UserController {



    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Autowired
    MemberDao memberDao;
    @Autowired
    UserService userService;
    @Autowired
    QkjTaskService qkjTaskService;
    @Autowired
    MemberService memberService;
    @Autowired
    QkjMemberTaskInfoDao qkjMemberTaskInfoDao;
    @Autowired
    MemberTaskInfoService memberTaskInfoService;


    @GetMapping("/personalCenter")
    @ApiOperation(value = "个人中心页面")
    public String personalCenter(
            @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from, HttpServletRequest req, Model model
    ){
        String refererUrl = req.getHeader("Referer");
        if(refererUrl!=null && refererUrl.contains("login")){
            model.addAttribute("fromlogin","1");
        }else{
            model.addAttribute("fromlogin","0");
        }
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/personal-center";
        } else {
            return "web/personalCenter/personalCenter";
        }
    }

    @GetMapping("/xieyi")
    @ApiOperation(value = "用户协议")
    public String xieyi(
            @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from
    ){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/xieyi.html";
        } else {
            return null;
        }
    }

    @GetMapping("/yinsi")
    @ApiOperation(value = "用户隐私")
    public String yinsi(
            @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from
    ){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/yinsi";
        } else {
            return null;
        }
    }
    @GetMapping("/yonghu")
    @ApiOperation(value = "用户信息保护及对策声明")
    public String yonghu(
            @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from
    ){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/yonghu";
        } else {
            return null;
        }
    }

    @GetMapping("/addSq")
    @ApiOperation(value = "加入社群")
    public String addSq(
            @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from
    ){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/addSq";
        } else {
            return "";
        }
    }


    @PostMapping("/getUserInfo")
    @ResponseBody
    @ApiOperation(value = "个人中心页面用户数据")
    public Result<QkjMemberDto> getUserInfo(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard
    ) throws ParseException {
        return userService.getUserInfo(memCard);
    }

    @PostMapping("/getUserInfoWeb")
    @ResponseBody
    @ApiOperation(value = "个人中心页面用户数据Web")
    public Result<QkjMemberDto> getUserInfoWeb(HttpServletRequest request) throws ParseException {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.getUserInfo(memCard);
    }


    @PostMapping("/loginUserImgWeb")
    @ResponseBody
    @ApiOperation(value = "")
    public Result loginUserImgWeb(HttpServletRequest request) throws ParseException {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.loginUserImgWeb(memCard);
    }


    @GetMapping("/buyRecord")
    @ApiOperation(value = "购买记录页面")
    public String buyRecord( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = false) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/buy-record";
        } else {
            return "web/personalCenter/purchaseRecords";
        }
    }

    @PostMapping("/buyRecordDetails")
    @ApiOperation(value = "购买记录信息")
    public Result buyRecordDetails(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard
    ){

        return null;
    }

    @GetMapping("/pointsMall")
    @ApiOperation(value = "积分商城")
    public String pointsMall(HttpServletRequest request,
                             @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from, Model model){
        String refererUrl = request.getHeader("Referer");
        if(refererUrl!=null && refererUrl.contains("login")){
            model.addAttribute("fromlogin","1");
        }else{
            model.addAttribute("fromlogin","0");
        }
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/points-mall";
        } else {
            return "web/personalCenter/intrgralMall";
        }
    }


    @GetMapping("/commodityDetail")
    @ApiOperation(value = "商品详情")
    public String commodityDetail(
            HttpServletRequest request,
            @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from,
            @ApiParam(name = "id",value = "商品id") @RequestParam(name = "id",required = true) Long id
    ){
        request.setAttribute("id",id);
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/commodity-detail";
        } else {
            return "";
        }
    }

    @GetMapping("/receiptInformation")
    @ApiOperation(value = "收货信息")
    public String receiptInformation(
            HttpServletRequest request,
            @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from,
            @ApiParam(name = "id",value = "商品id") @RequestParam(name = "id",required = true) Long id
    ){
        request.setAttribute("id",id);
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/receipt-information";
        } else {
            return "";
        }
    }


    @GetMapping("/userExchange")
    @ApiOperation(value = "兑换的商品")
    public String userExchange( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/user-exchange";
        } else {
            return "";
        }
    }


    @GetMapping("/userStudyRecord")
    @ApiOperation(value = "学习记录")
    public String userStudyRecord( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/user-study-record";
        } else {
            return "web/personalCenter/learningRecord";
        }
    }

    @GetMapping("/callWe")
    @ApiOperation(value = "联系我们")
    public String callWe( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/call-we";
        } else {
            return "web/personalCenter/contactUs";
        }
    }

    @GetMapping("/userAccountNumber")
    @ApiOperation(value = "我的账号")
    public String userAccountNumber( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/user-account-number";
        } else {
            return "web/personalCenter/myAccount";
        }
    }

    @GetMapping("/editPass")
    @ApiOperation(value = "修改密码")
    public String editPass( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/edit-pass";
        } else {
            return "web/personalCenter/editPass";
        }
    }

    @GetMapping("/privacy")
    @ApiOperation(value = "隐私条款")
    public String privacy( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "";
        } else {
            return "web/personalCenter/privacyPolicy";
        }
    }

    @GetMapping("/registration")
    @ApiOperation(value = "注册协议")
    public String registration( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "";
        } else {
            return "web/personalCenter/registrationProtocol";
        }
    }

    @GetMapping("/userinfo")
    @ApiOperation(value = "用户信息保护及对策声明")
    public String userinfo( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "";
        } else {
            return "web/personalCenter/userinfo";
        }
    }

    @GetMapping("/aboutWe")
    @ApiOperation(value = "关于我们")
    public String aboutWe( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/about-we";
        } else {
            return "web/personalCenter/aboutUs";
        }
    }

    @GetMapping("/certificationSm")
    @ApiOperation(value = "实名认证")
    public String certificationSm( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/certification-sm";
        } else {
            return "web/personalCenter/realNameAuthentication";
        }
    }
    @GetMapping("/certificationSmojl")
    @ApiOperation(value = "实名认证")
    public String certificationSmojl( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/certification-smojl";
        } else {
            return "web/personalCenter/realNameAuthentication";
        }
    }

    @GetMapping("/certificationYs")
    @ApiOperation(value = "医师认证")
    public String certificationYs( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/certification-ys";
        } else {
            return "web/personalCenter/physicianCertification";
        }
    }
    @GetMapping("/certificationYsojl")
    @ApiOperation(value = "医师认证")
    public String certificationYsojl( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "html5/user/certification-ysojl";
        } else {
            return "web/personalCenter/physicianCertification";
        }
    }

    @GetMapping("/myCollection")
    @ApiOperation(value = "我的收藏")
    public String myCollection( @ApiParam(name = "from",value = "请求类型 web：网站 H5：手机端") @RequestParam(name = "from",required = true) String from){
        if (StringUtils.isNotBlank(from) && from.equals("H5")) {
            return "";
        } else {
            return "web/personalCenter/myCollection";
        }
    }

    @PostMapping("/singDay")
    @ResponseBody
    @ApiOperation(value = "个人签到")
    public Result singDay(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard,
            @ApiParam(name = "dayPoints",value = "每天的积分") @RequestParam(name = "dayPoints",required = true) Integer dayPoints
    ) {
        return qkjTaskService.dailyCheckIn(memCard,18,dayPoints);
    }


    @PostMapping("/singDayWeb")
    @ResponseBody
    @ApiOperation(value = "个人签到Web")
    public Result singDayWeb(
            @ApiParam(name = "dayPoints",value = "每天的积分") @RequestParam(name = "dayPoints",required = true) Integer dayPoints,HttpServletRequest request
    ) throws ParseException {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return qkjTaskService.dailyCheckInQd(memCard,18,dayPoints);
    }



    @PostMapping("/uploadHearderImg")
    @ResponseBody
    @ApiOperation(value = "")
    public Result uploadHearderImg(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard,
            @ApiParam(name = "file",value = "上传的文件") @RequestParam("file") MultipartFile file,
            @ApiParam(name = "type",value = "请求类型") @RequestParam("type") Integer type
    ) throws FileNotFoundException {
        String filename = file.getOriginalFilename();
        String key = "html5/images/"+UUID.getUUID()+filename;
        File file1 = OSSUtils.MultipartFileToFile(file);
        try {
            OSSUtils.uploadFileNew("qkj-web",key,file1,"image/jpeg");
            if (type == 1) {
                //从用户中心点击头像进来
                return userService.changeUserHeader(key, memCard);
            } else {
                //从个人中心修改用户信息处来
                return Result.success("https://files.qkyxzx.com/"+key);
            }

        } catch (Exception e) {
            return Result.failed(BizCodeEnum.UPLOAD_IMG_ERROR);
        }
    }


    @PostMapping("/uploadHearderImgWeb")
    @ResponseBody
    @ApiOperation(value = "")
    public Result uploadHearderImgWeb(
            @ApiParam(name = "file",value = "上传的文件") @RequestParam("file") MultipartFile file,
            @ApiParam(name = "type",value = "请求类型") @RequestParam("type") Integer type,
            HttpServletRequest request
    ) throws FileNotFoundException {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        String filename = file.getOriginalFilename();
        String key = "html5/images/"+UUID.getUUID()+filename;
        File file1 = OSSUtils.MultipartFileToFile(file);
        try {
            OSSUtils.uploadFileNew("qkj-web",key,file1,"image/jpeg");
            if (type == 1) {
                //从用户中心点击头像进来
                return userService.changeUserHeader(key, memCard);
            } else {
                //从个人中心修改用户信息处来
                return Result.success("https://files.qkyxzx.com/"+key);
            }
        } catch (Exception e) {
            return Result.failed(BizCodeEnum.UPLOAD_IMG_ERROR);
        }
    }


    @PostMapping("/findUserTaskInfo")
    @ResponseBody
    @ApiOperation(value = "获取用户积分明细")
    public Result findUserTaskInfo(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard
    ) {
        return qkjTaskService.findUserTaskInfo(memCard);
    }

    @PostMapping("/findUserTaskInfoWeb")
    @ResponseBody
    @ApiOperation(value = "获取用户积分明细Web")
    public Result findUserTaskInfoWeb(HttpServletRequest request) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return qkjTaskService.findUserTaskInfo(memCard);
    }

    @PostMapping("/findUserTaskList")
    @ResponseBody
    @ApiOperation(value = "获取用户任务列表")
    public Result findUserTaskList(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard
    ) {
        return qkjTaskService.findUserTaskList(memCard);
    }

    @PostMapping("/findUserTaskListWeb")
    @ResponseBody
    @ApiOperation(value = "获取用户任务列表Web")
    public Result findUserTaskListWeb(HttpServletRequest request){
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return qkjTaskService.findUserTaskList(memCard);
    }


    @PostMapping("/findUserjfRanking")
    @ResponseBody
    @ApiOperation(value = "获取用户排行榜")
    public Result findUserjfRanking(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard
    ) {
        return qkjTaskService.findUserjfRanking(memCard);
    }

    @PostMapping("/findUserjfRankingWeb")
    @ResponseBody
    @ApiOperation(value = "获取用户排行榜Web")
    public Result findUserjfRankingWeb(HttpServletRequest request) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return qkjTaskService.findUserjfRanking(memCard);
    }


    @PostMapping("/findGoodMallList")
    @ResponseBody
    @ApiOperation(value = "获取积分兑换商品列表")
    public Result findGoodMallList(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard,
            @ApiParam(name = "jfPage",value = "") @RequestParam(name = "jfPage",required = false) Integer jfPage,
            @ApiParam(name = "jfSize",value = "") @RequestParam(name = "jfSize",required = false) Integer jfSize)
    {
        return userService.findGoodMallList(memCard,jfPage,jfSize);
    }

    @PostMapping("/findGoodMallListWeb")
    @ResponseBody
    @ApiOperation(value = "获取积分兑换商品列表Web")
    public Result findGoodMallList(HttpServletRequest request,
                                   @ApiParam(name = "jfPage",value = "") @RequestParam(name = "jfPage",required = false) Integer jfPage,
                                   @ApiParam(name = "jfSize",value = "") @RequestParam(name = "jfSize",required = false) Integer jfSize)
    {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.findGoodMallList(memCard,jfPage,jfSize);
    }


    @PostMapping("/findGoodDetails")
    @ResponseBody
    @ApiOperation(value = "获取商品详情")
    public Result findGoodDetails(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard,
            @ApiParam(name = "id",value = "商品详情") @RequestParam(name = "id",required = true) Long id
    ) {
        return userService.findGoodDetails(memCard,id);
    }



    @PostMapping("/findGoodDetailsWeb")
    @ResponseBody
    @ApiOperation(value = "获取商品详情Web")
    public Result findGoodDetailsWeb(
            @ApiParam(name = "id",value = "商品详情") @RequestParam(name = "id",required = true) Long id,
            HttpServletRequest request
    ) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.findGoodDetails(memCard,id);
    }

    @PostMapping("/integralLevel")
    @ResponseBody
    @ApiOperation(value = "积分等级")
    public Result integralLevel(HttpServletRequest request) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.integralLevel(memCard);
    }



    @PostMapping("/findUserGoodList")
    @ResponseBody
    @ApiOperation(value = "获取用户兑换的商品列表")
    public Result findUserGoodList(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard,
            @ApiParam(name = "start",value = "起始页") @RequestParam(name = "start",required = true) Integer start,
            @ApiParam(name = "size",value = "每页显示条数") @RequestParam(name = "size",required = true) Integer size
    ) {
        return userService.findUserGoodList(memCard,start,size);
    }

    @PostMapping("/findUserGoodListWeb")
    @ResponseBody
    @ApiOperation(value = "获取用户兑换的商品列表Web")
    public Result findUserGoodListWeb(
            @ApiParam(name = "start",value = "起始页") @RequestParam(name = "start",required = true) Integer start,
            @ApiParam(name = "size",value = "每页显示条数") @RequestParam(name = "size",required = true) Integer size,
            HttpServletRequest request
    ) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.findUserGoodList(memCard,start,size);
    }


    @PostMapping("/findUserOrderList")
    @ResponseBody
    @ApiOperation(value = "获取用户购买记录列表")
    public Result findUserOrderList(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = true) String memCard,
            @ApiParam(name = "start",value = "起始页") @RequestParam(name = "start",required = true) Integer start,
            @ApiParam(name = "size",value = "每页显示条数") @RequestParam(name = "size",required = true) Integer size,
            @ApiParam(name = "type",value = "查询类型  -1是全部") @RequestParam(name = "type",required = true) Integer type
    ) {
        return userService.findUserOrderList(memCard,start,size,type);
    }

    @PostMapping("/findUserAllOrderList")
    @ResponseBody
    @ApiOperation(value = "获取用户所有购买记录列表H5")
    public Result findUserAllOrderList(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = true) String memCard
    ) {

        return userService.findUserAllOrderList(memCard);
    }

    @PostMapping("/findUserAllOrderListWeb")
    @ResponseBody
    @ApiOperation(value = "获取用户所有购买记录列表Web")
    public Result findUserAllOrderListWeb(
//            @ApiParam(name = "start",value = "起始页") @RequestParam(name = "start",required = true) Integer start,
//            @ApiParam(name = "size",value = "每页显示条数") @RequestParam(name = "size",required = true) Integer size,
//            @ApiParam(name = "type",value = "查询类型  -1是全部") @RequestParam(name = "type",required = true) Integer type,
            HttpServletRequest request
    ) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.findUserAllOrderList(memCard);
    }

    @PostMapping("/findUserOrderListWeb")
    @ResponseBody
    @ApiOperation(value = "获取用户购买记录列表Web")
    public Result findUserOrderListWeb(
            @ApiParam(name = "start",value = "起始页") @RequestParam(name = "start",required = true) Integer start,
            @ApiParam(name = "size",value = "每页显示条数") @RequestParam(name = "size",required = true) Integer size,
            @ApiParam(name = "type",value = "查询类型  -1是全部") @RequestParam(name = "type",required = true) Integer type,
            HttpServletRequest request
    ) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.findUserOrderList(memCard,start,size,type);
    }


    @PostMapping("/findUserCollectionListWeb")
    @ResponseBody
    @ApiOperation(value = "获取用户收藏列表Web")
    public Result findUserCollectionListWeb(
            @ApiParam(name = "start",value = "起始页") @RequestParam(name = "start",required = true) Integer start,
            @ApiParam(name = "size",value = "每页显示条数") @RequestParam(name = "size",required = true) Integer size,
            @ApiParam(name = "type",value = "查询类型  -1是全部") @RequestParam(name = "type",required = true) Integer type,
            HttpServletRequest request
    ) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.findUserCollectionList(memCard,start,size,type);
    }

    @PostMapping("/saveCollectionWeb")
    @ResponseBody
    @ApiOperation(value = "保存用户收藏")
    public Result saveCollectionWeb(
            @ApiParam(name = "typeId",value = "内容id") @RequestParam(name = "typeId",required = true) String typeId,
            @ApiParam(name = "type",value = "内容类型 1:课程 2:直播 3:会议 4:课件 ") @RequestParam(name = "type",required = true) Integer type,
            @ApiParam(name = "isDel",value = "是否取消收藏 1取消收藏 2收藏") @RequestParam(name = "isDel",required = true) Integer isDel,
            @ApiParam(name = "id",value = "id不必填") @RequestParam(name = "id",required = false) Integer id,
            HttpServletRequest request
    ) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.saveCollectionWeb(memCard,typeId,type,isDel,id);
    }




    @PostMapping("/findUserInfoWithSm")
    @ResponseBody
    @ApiOperation(value = "获取用户实名认证信息")
    public Result findUserInfoWithSm(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard
    ) {
        return userService.findUserInfoWithSm(memCard);
    }

    @PostMapping("/findUserInfoWithSmWeb")
    @ResponseBody
    @ApiOperation(value = "获取用户实名认证信息Web")
    public Result findUserInfoWithSmWeb(HttpServletRequest request) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.findUserInfoWithSm(memCard);
    }


    @PostMapping("/findUserInfoWithYsWeb")
    @ResponseBody
    @ApiOperation(value = "获取用户医师认证信息Web")
    public Result findUserInfoWithYsWeb(HttpServletRequest request) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.findUserInfoWithYs(memCard);
    }

    @PostMapping("/saveUserInfoWithSm")
    @ResponseBody
    @ApiOperation(value = "保存用户实名认证信息")
    public Result saveUserInfoWithSm(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard,
            @RequestParam(name = "userName",required = true) String userName,
            @RequestParam(name = "card",required = true) String card,
            @RequestParam(name = "unitName",required = true) String unitName,
            @RequestParam(name = "address",required = true) String address,
            @RequestParam(name = "addressXx",required = false) String addressXx,
            @RequestParam(name = "experience",required = true) String experience,
            @RequestParam(name = "sex",required = true) String sex,
            @RequestParam(name = "email",required = false) String email,
            @RequestParam(name = "documentType",required = false) Integer documentType,
            @RequestParam(name = "documentNumber",required = false) String documentNumber,
            @RequestParam(name = "degree",required = false) Integer degree,
            @RequestParam(name = "bachelorDegree",required = false) Integer bachelorDegree,
            @RequestParam(name = "occupationType",required = false) Integer occupationType,
            @RequestParam(name = "unitArea",required = false) Integer unitArea,
            @RequestParam(name = "unitAddress",required = false) String unitAddress,
            @RequestParam(name = "specialization",required = false) String specialization
    ) {
        return userService.saveUserInfoWithSm(memCard,userName,card,unitName,
                                              address,addressXx,experience,sex,email,documentType,
                                              documentNumber,degree,bachelorDegree,occupationType,
                                              unitArea,unitAddress,specialization);
    }


    @PostMapping("/saveUserInfoWithSmWeb")
    @ResponseBody
    @ApiOperation(value = "保存用户实名认证信息Web")
    public Result saveUserInfoWithSmWeb(
            @RequestParam(name = "userName",required = true) String userName,
            @RequestParam(name = "card",required = true) String card,
            @RequestParam(name = "unitName",required = true) String unitName,
            @RequestParam(name = "address",required = true) String address,
            @RequestParam(name = "addressXx",required = false) String addressXx,
            @RequestParam(name = "experience",required = true) String experience,
            @RequestParam(name = "sex",required = true) String sex,
            @RequestParam(name = "email",required = false) String email,
            @RequestParam(name = "documentType",required = false) Integer documentType,
            @RequestParam(name = "documentNumber",required = false) String documentNumber,
            @RequestParam(name = "degree",required = false) Integer degree,
            @RequestParam(name = "bachelorDegree",required = false) Integer bachelorDegree,
            @RequestParam(name = "occupationType",required = false) Integer occupationType,
            @RequestParam(name = "unitArea",required = false) Integer unitArea,
            @RequestParam(name = "unitAddress",required = false) String unitAddress,
            @RequestParam(name = "specialization",required = false) String specialization,
            HttpServletRequest request
    ) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.saveUserInfoWithSm(memCard,userName,card,unitName,
                address,addressXx,experience,sex,email,documentType,
                documentNumber,degree,bachelorDegree,occupationType,
                unitArea,unitAddress,specialization);
    }

    @PostMapping("/findUserInfoWithYs")
    @ResponseBody
    @ApiOperation(value = "获取用户医师认证信息")
    public Result findUserInfoWithYs(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard
    ) {
        return userService.findUserInfoWithYs(memCard);
    }

    @PostMapping("/saveUserInfoWithYs")
    @ResponseBody
    @ApiOperation(value = "保存用户医师认证信息")
    public Result saveUserInfoWithYs(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard,
            @RequestParam(name = "professional",required = true) Integer professional,
            @RequestParam(name = "professionalTwo",required = true) Integer professionalTwo,
            @RequestParam(name = "businessLicense",required = true) String businessLicense,
            @RequestParam(name = "post",required = true) Integer post
    ) {
        return userService.saveUserInfoWithYsNew(memCard,businessLicense,professional,professionalTwo,post);
    }

    @PostMapping("/saveUserInfoWithYsWeb")
    @ResponseBody
    @ApiOperation(value = "保存用户医师认证信息Web")
    public Result saveUserInfoWithYsWeb(
            @RequestParam(name = "businessLicense",required = true) String businessLicense,
            @RequestParam(name = "professional",required = true) Integer professional,
            @RequestParam(name = "professionalTwo",required = true) Integer professionalTwo,
            @RequestParam(name = "post",required = true) Integer post,
            HttpServletRequest request
    ) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.saveUserInfoWithYsNew(memCard,businessLicense,professional,professionalTwo,post);
    }

    @PostMapping("/saveUserInfoWithSmAndYs")
    @ResponseBody
    @ApiOperation(value = "保存用户认证信息")
    public Result saveUserInfoWithSmAndYsV2(
            HttpServletRequest request,
            @ApiParam(name = "memCard", value = "用户唯一标识") @RequestAttribute(name = "memCard", required = false) String memCard,
            @RequestParam(name = "userName", required = false) String userName,
            @RequestParam(name = "card", required = false) String card,
            @RequestParam(name = "unitName", required = false) String unitName,
            @RequestParam(name = "department", required = false) String department,
            @RequestParam(name = "address", required = false) String address,
            @RequestParam(name = "addressXx", required = false) String addressXx,
            @RequestParam(name = "experience", required = false) String experience,
            @RequestParam(name = "sex", required = false) String sex,
            @RequestParam(name = "email", required = false) String email,
            @RequestParam(name = "documentType", required = false) Integer documentType,
            @RequestParam(name = "documentNumber", required = false) String documentNumber,
            @RequestParam(name = "degree", required = false) Integer degree,
            @RequestParam(name = "bachelorDegree", required = false) Integer bachelorDegree,
            @RequestParam(name = "occupationType", required = false) Integer occupationType,
            @RequestParam(name = "professional", required = false) Integer professional,
            @RequestParam(name = "professionalTwo", required = false) Integer professionalTwo,
            @RequestParam(name = "businessLicense", required = false) String businessLicense,
            @RequestParam(name = "post", required = false) Integer post,
            @RequestParam(name = "province", required = false) String province,
            @RequestParam(name = "city", required = false) String city,
            @RequestParam(name = "unitArea", required = false) Integer unitArea,
            @RequestParam(name = "unitAddress", required = false) String unitAddress,
            @RequestParam(name = "specialization", required = false) String specialization,
            @RequestParam(name = "attestType", required = false) Integer attestType,
            @RequestParam(name = "source", required = false) Integer source
    ) {

        if (StringUtils.isBlank(memCard)) {
            memCard = UserLoginUtil.isUserLogin(request);
        }
        if (StringUtils.isEmpty(memCard)) {
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        //判断是什么类型的实名认证
        Result result = null;
        switch (attestType) {
            case SaveYsAndSmConsts.ATTEST_TYPE_A:
                if (StringUtils.isBlank(businessLicense)) {
                    result = Result.failed(BizCodeEnum.PARAM_NULL);
                } else {
                    result = userService.saveUserInfoWithYsNew(memCard, businessLicense, professional, professionalTwo, post);
                }

                break;
            case SaveYsAndSmConsts.ATTEST_TYPE_B:
                if (StringUtils.isBlank(userName) || Objects.isNull(card) || Objects.isNull(sex)) {
                    result = Result.failed(BizCodeEnum.PARAM_NULL);
                } else {
                    result = userService.saveUserInfoWithSm(memCard, userName, card, unitName,
                            address, addressXx, experience, sex, email, documentType,
                            documentNumber, degree, bachelorDegree, occupationType,
                            unitArea, unitAddress, specialization);
                }

                break;
            case SaveYsAndSmConsts.ATTEST_TYPE_C:

                if ((StringUtils.isBlank(department) || StringUtils.isBlank(unitName) || StringUtils.isBlank(businessLicense) || StringUtils.isBlank(userName)) && !Objects.equals(1, source)) {
                    result = Result.failed(BizCodeEnum.PARAM_NULL);
                } else {
                    boolean needCheck = true;
                    if (Objects.equals(1, source) && StringUtils.isBlank(businessLicense)) {//如果是分享来源，并且没有传医师证号跳过校验
                        needCheck = false;
                    }
                    result = userService.saveUserInfoWithYsNewV2(memCard, userName, unitName, sex,
                            department, province, city, businessLicense, professional, professionalTwo, post, needCheck);
                }

                break;
            case SaveYsAndSmConsts.ATTEST_TYPE_D:

                if (StringUtils.isBlank(userName) || Objects.isNull(card) || Objects.isNull(sex) || StringUtils.isBlank(businessLicense)) {
                    result = Result.failed(BizCodeEnum.PARAM_NULL);
                } else {
                    result = userService.saveUserInfoWithSmV2(memCard, userName, card, unitName,
                            address, addressXx, experience, sex, email, documentType,
                            documentNumber, degree, bachelorDegree, occupationType,
                            unitArea, unitAddress, specialization, department, province, city, businessLicense, post);
                }

                break;
            default:
                result = Result.failed(BizCodeEnum.PARAM_NULL);
        }
        return result;

    }

    @PostMapping("/updateUserInfo")
    @ResponseBody
    @ApiOperation(value = "更改用户信息")
    public Result updateUserInfo(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard,
            @RequestParam(name = "userName",required = false) String userName,
            @RequestParam(name = "phone",required = false) String phone,
            @RequestParam(name = "headerImg",required = true) String headerImg,
            @ApiParam(name = "valCode", value = "验证码") @RequestParam(name = "valCode", required = false) String valCode
    ){

        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        if (StringUtils.isNotBlank(valCode)) {
            int valRs = validateMobileYzm(phone, valCode);
            if("qk,#234abc343,".equalsIgnoreCase(valCode)){
                log.info("updateUserInfoWeb"+phone);
                valRs = 0;
            }
            log.info("----------------校验用户验证码结果-----------------------" + valRs);
            if (valRs == -1) {
                log.info("验证码已过期");
                return Result.failed(BizCodeEnum.CODE_TIME_OUT);
            }
            if (valRs == -2) {
                log.info("验证码错误");
                return Result.failed(BizCodeEnum.CODE_ERROR);
            }
        }
        //校验用户名的唯一性
        if(StringUtils.isNotBlank(userName)){
            List<QkjMember> qkjMembers = memberDao.listByMemNickname(userName);
            if(CollectionUtils.isNotEmpty(qkjMembers) && qkjMembers.size() >=1){
                return Result.failed(BizCodeEnum.NAME_REPEAT);
            }
        }
        //校验手机号的唯一性
        if (StringUtils.isNotBlank(phone)) {
            QkjMember member = memberDao.findByMemMobile(phone);

            if (Objects.nonNull(member)) {
                return Result.failed(BizCodeEnum.PHONE_REGISTER);
            }
        }

        return userService.UpdateUserInfo(memCard,userName,phone,headerImg);
    }

    private int validateMobileYzm(String memUserId, String inputYzm) {

        String realYzm = (String) stringRedisTemplate.opsForValue().get(memUserId + "yzm");
        log.info("UserController 用户输入的验证码 " + inputYzm);
        log.info("UserController 缓存里面的验证码" + realYzm);
        if (realYzm == null) {
            return -1;
        }

        if (!inputYzm.equals(realYzm)) {
            return -2;
        }

        stringRedisTemplate.delete(memUserId + "yzm");
        return 0;
    }

    @PostMapping("/updateUserInfoWeb")
    @ResponseBody
    @ApiOperation(value = "更改用户信息Web")
    public Result updateUserInfoWeb(
            @RequestParam(name = "userName",required = false) String userName,
            @RequestParam(name = "phone",required = false) String phone,
            @RequestParam(name = "headerImg",required = true) String headerImg,
            @ApiParam(name = "valCode", value = "验证码") @RequestParam(name = "valCode", required = false) String valCode,
            HttpServletRequest request
    ){
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }

        if (StringUtils.isNotBlank(valCode)) {
            int valRs = validateMobileYzm(phone, valCode);
            if("qk,#234abc343,".equalsIgnoreCase(valCode)){
                log.info("updateUserInfoWeb"+phone);
                valRs = 0;
            }
            log.info("----------------校验用户验证码结果-----------------------" + valRs);
            if (valRs == -1) {
                log.info("验证码已过期");
                return Result.failed(BizCodeEnum.CODE_TIME_OUT);
            }
            if (valRs == -2) {
                log.info("验证码错误");
                return Result.failed(BizCodeEnum.CODE_ERROR);
            }
        }

        //校验用户名的唯一性
        if(StringUtils.isNotBlank(userName)){
            List<QkjMember> qkjMembers = memberDao.listByMemNickname(userName);
            if(CollectionUtils.isNotEmpty(qkjMembers) && qkjMembers.size() >=1){
                return Result.failed(BizCodeEnum.NAME_REPEAT);
            }
        }
        //校验手机号的唯一性
        if (StringUtils.isNotBlank(phone)) {
            QkjMember member = memberDao.findByMemMobile(phone);

            if (Objects.nonNull(member)) {
                return Result.failed(BizCodeEnum.PHONE_REGISTER);
            }
        }

        return userService.UpdateUserInfo(memCard,userName,phone,headerImg);
    }


    @PostMapping("/findUserStudyRecord")
    @ResponseBody
    @ApiOperation(value = "查询用户学习记录")
    public Result findUserStudyRecord(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard,
            @ApiParam(name = "start",value = "起始页") @RequestParam(name = "start",required = true) Integer start,
            @ApiParam(name = "size",value = "每页显示条数") @RequestParam(name = "size",required = true) Integer size
    ){
        return userService.findUserStudyRecord(memCard,start,size);
    }

    @PostMapping("/findUserStudyRecordWeb")
    @ResponseBody
    @ApiOperation(value = "查询用户学习记录Web")
    public Result findUserStudyRecordWeb(
            @ApiParam(name = "start",value = "起始页") @RequestParam(name = "start",required = true) Integer start,
            @ApiParam(name = "size",value = "每页显示条数") @RequestParam(name = "size",required = true) Integer size,
            HttpServletRequest request
    ){
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.findUserStudyRecordWeb(memCard,start,size);
    }

    @PostMapping("/findUserBaseInfo")
    @ResponseBody
    @ApiOperation(value = "获取用户基本信息")
    public Result findUserBaseInfo(HttpServletRequest request,
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard
    ) {
        if (request.getSession().getAttribute("UserCard") != null) {
            memCard = (String) request.getSession().getAttribute("UserCard");
        }
        return Result.success(memberService.findByMemCard(memCard));
    }

    @PostMapping("/findUserAttestInfo")
    @ResponseBody
    @ApiOperation(value = "获取用户认证的基本信息")
    public Result findUserAttestInfo(HttpServletRequest request,
                                      @ApiParam(name = "memCard", value = "用户唯一标识") @RequestAttribute(name = "memCard", required = false) String memCard
    ) {
        if (StringUtils.isBlank(memCard)) {
            memCard = UserLoginUtil.isUserLogin(request);
        }
        return userService.findUserAttestInfo(memCard);
    }


    @PostMapping("/findUserIntegral")
    @ResponseBody
    @ApiOperation(value = "获取用户积分")
    public Result findUserIntegral(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard
    ) {
        return Result.success(memberService.findUserIntegral(memCard));
    }

    @PostMapping("/saveReceiptInformation")
    @ResponseBody
    @ApiOperation(value = "保存收货地址")
    public Result saveReceiptInformation(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard,
            @RequestParam(name = "name",required = true) String name,
            @RequestParam(name = "phone",required = true) String phone,
            @RequestParam(name = "adress",required = true) String adress,
            @ApiParam(name = "id",value = "商品id") @RequestParam(name = "id",required = false) Long id,
            HttpServletRequest request
    ) {
        return userService.saveReceiptInformation(memCard,id,name,phone,adress);
    }

    @PostMapping("/saveReceiptInformationWeb")
    @ResponseBody
    @ApiOperation(value = "保存收货地址web")
    public Result saveReceiptInformationWeb(
            @RequestParam(name = "name",required = true) String name,
            @RequestParam(name = "phone",required = true) String phone,
            @RequestParam(name = "adress",required = true) String adress,
            @ApiParam(name = "id",value = "商品id") @RequestParam(name = "id",required = false) Long id,
            HttpServletRequest request
    ) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        return userService.saveReceiptInformation(memCard,id,name,phone,adress);
    }

    @PostMapping("/getQrImg")
    @ResponseBody
    @ApiOperation(value = "查询社群二维码")
    public Result getQrImg(
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard
    ) {
        return userService.getQrImg(memCard);
    }

    @PostMapping("/saveUserDorec")
    @ResponseBody
    @ApiOperation(value = "添加浏览记录/分享记录")
    public Result saveUserDorec(
            HttpServletRequest request,
            @ApiParam(name = "memCard",value = "用户唯一标识") @RequestAttribute(name = "memCard",required = false) String memCard,
            @ApiParam(name = "oprType",value = "操作类型，1-浏览，2-分享") @RequestParam(name = "oprType") Integer oprType,
            @ApiParam(name = "objType",value = "类型 1:文章") @RequestParam(name = "objType",required = false) Integer objType,
            @ApiParam(name = "objId",value = "类型对应的ID") @RequestParam(name = "objId",required = false) Integer objId,
            @ApiParam(name = "source",value = "来源 1:h5 2:pc") @RequestParam(name = "source",required = false) Integer source,
            @ApiParam(name = "url",value = "操作类型，1-浏览，2-分享") @RequestParam(name = "url",required = false) String url
    ) {
        String ip = IpUtil.getIpAddr(request);
        return userService.saveUserDorec(memCard, oprType, objType, objId, source, url, ip);
    }


    @PostMapping("/saveUserDorecWeb")
    @ResponseBody
    @ApiOperation(value = "添加浏览记录/分享记录Web")
    public Result saveUserDorecWeb(
            HttpServletRequest request,
            @ApiParam(name = "oprType",value = "操作类型，1-浏览，2-分享") @RequestParam(name = "oprType") Integer oprType,
            @ApiParam(name = "objType",value = "类型 1:文章") @RequestParam(name = "objType",required = false) Integer objType,
            @ApiParam(name = "objId",value = "类型对应的ID") @RequestParam(name = "objId",required = false) Integer objId,
            @ApiParam(name = "source",value = "来源 1:h5 2:pc") @RequestParam(name = "source",required = false) Integer source,
            @ApiParam(name = "url",value = "操作类型，1-浏览，2-分享") @RequestParam(name = "url",required = false) String url
    ) {
        String memCard=UserLoginUtil.isUserLogin(request);
        if(StringUtils.isEmpty(memCard)){
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        String ip = "";
        return userService.saveUserDorec(memCard, oprType, objType, objId, source, url, ip);
    }

    @PostMapping("/updateAllIDNumber")
    @ResponseBody
    @ApiOperation("更新数据库中明文身份证号码为密文")
    public Map<String, String> encryptedIDNumber() {
        userService.updateAllIDNumber();
        Map<String, String> a = new LinkedHashMap<>();
        a.put("message", "成功");
        return a;
    }

    @PostMapping("/isFinishFirstLoginTask")
    @ResponseBody
    @ApiOperation("是否完成首次任务赠送积分")
    public Result whetherFinishFirstLoginTask(
            HttpServletRequest request,
            @ApiParam(name = "memCard", value = "用户唯一标识") @RequestAttribute(name = "memCard", required = false) String memCard
    ) {
        if (StringUtils.isBlank(memCard)) {//pc从session去 m从参数取
            memCard = UserLoginUtil.isUserLogin(request);
        }

        if (StringUtils.isEmpty(memCard)) {
            return Result.failed(BizCodeEnum.NO_LOGIN);
        }
        final boolean finish = memberTaskInfoService.whetherFinishFirstLoginTask(memCard);
        if (!finish) {//增加积分
            try {
                memberTaskInfoService.increasePoints(memCard, TaskConsts.FIRST_LOGIN_TASK);
                Map<String, Boolean> resultMap = new LinkedHashMap<>();
                resultMap.put("finish", true);
                return Result.success(resultMap);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        Map<String, Boolean> resultMap = new LinkedHashMap<>();
        resultMap.put("finish", false);
        return Result.success(resultMap);
    }



}
