package com.cirle.scientific.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cirle.scientific.constants.TaskConsts;
import com.cirle.scientific.dao.*;
import com.cirle.scientific.dto.*;
import com.cirle.scientific.po.*;
import com.cirle.scientific.pojo.BizCodeEnum;
import com.cirle.scientific.pojo.Result;
import com.cirle.scientific.service.QkjTaskService;
import com.cirle.scientific.service.SysRegionService;
import com.cirle.scientific.service.UserService;
import com.cirle.scientific.utils.*;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.Comparator.comparing;


@Service
@Slf4j
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;
    @Autowired
    QkjXySiginDao qkjXySiginDao;
    @Autowired
    QkjMemberTaskInfoDao qkjMemberTaskInfoDao;
    @Autowired
    MemberDao memberDao;
    @Autowired
    QkjIntegralGoodsDao qkjIntegralGoodsDao;

    @Autowired
    QkjMemberTaskDetailDao qkjMemberTaskDetailDao;

    @Autowired
    QkjIntegralDetailDao qkjIntegralDetailDao;
    @Autowired
    OrderDao orderDao;
    @Autowired
    CollectionDao collectionDao;

    @Autowired
    QkjTqcourseDao qkjTqcourseDao;
    @Autowired
    QkjLiveDao qkjLiveDao;
    @Autowired
    QkjMemberPersonalAuthDao qkjMemberPersonalAuthDao;
    @Autowired
    QkjCertificatePhysiciansDao qkjCertificatePhysiciansDao;
    @Autowired
    QkjTaskService qkjTaskService;
    @Autowired
    QkjVedioPlayRecordLogDao qkjVedioPlayRecordLogDao;

    @Autowired
    QkjTqcourseCourseDao qkjTqcourseCourseDao;

    @Autowired
    QkjCommunityDao qkjCommunityDao;

    @Autowired
    QkjVedioPlayRecordDao qkjVedioPlayRecordDao;

    @Autowired
    QkjCourseWareDao qkjCourseWareDao;
    @Autowired
    QkjConferenceDao qkjConferenceDao;

    @Autowired
    QkjMemberDorecDao memberDorecDao;

    @Autowired
    QkjTaskService taskService;

    @Autowired
    QkjVideoPlayLogDao qkjVideoPlayLogDao;

    @Autowired
    private IdentificationNumberEncryptor identificationNumberEncryptor;

    @Autowired
    RegionDao regionDao;

    @Override
    public Result<QkjMemberDto> getUserInfo(String memCard) throws ParseException {
        log.info("user===memCard====" + memCard);
        QkjMemberDto qkjMemberDto = CopyUtil.copy(userDao.findUserByMemCard(memCard), QkjMemberDto.class);
        //查询签到次数
        List<DaliyCheckInDTO> sign = sign(memCard);
        for (DaliyCheckInDTO daliyCheckInDTO : sign) {
            if (daliyCheckInDTO.getIsCuur() == 1) {
                if (daliyCheckInDTO.getIsTodayChenckIn() == 1) {
                    qkjMemberDto.setSiginStatus(1);
                } else {
                    qkjMemberDto.setSiginStatus(0);
                }
                qkjMemberDto.setDayPoints(daliyCheckInDTO.getDayPoints());
            }
        }
        qkjMemberDto.setSign(sign);
        //查询我的积分
        QkjMemberTaskInfo byMemCard = qkjMemberTaskInfoDao.findByMemCard(memCard);
        if (byMemCard != null) {
            qkjMemberDto.setMemTotalPoints(byMemCard.getMemTotalPoints());
            qkjMemberDto.setMemResidualPoints(byMemCard.getMemResidualPoints());
        }
        //查询加入时间
        Calendar memRegisterTime = qkjMemberDto.getMemRegisterTime();
        if (memRegisterTime != null) {
            Date time = memRegisterTime.getTime();
            int days = DateUtil.differentDays(time, new Date());
            qkjMemberDto.setDays(days);
        }
        return Result.success(qkjMemberDto);
    }

    @Override
    public Result loginUserImgWeb(String memCard) {
        Map<String, Object> map = new HashMap<>();
        //查询我的积分
        QkjMemberTaskInfo byMemCard = qkjMemberTaskInfoDao.findByMemCard(memCard);
        if (byMemCard == null) {
            map.put("memTotalPoints", 0);
        } else {
            map.put("memTotalPoints", byMemCard.getMemTotalPoints());
        }
        //查询头像
        QkjMemberDto qkjMemberDto = CopyUtil.copy(userDao.findUserByMemCard(memCard), QkjMemberDto.class);
        map.put("memHeadimg", qkjMemberDto.getMemHeadimg());
        return Result.success(map);
    }
/*

    @Override
    public Result findGoodMallList(String memCard,Integer page,Integer size) {
        JSONObject data = new JSONObject();
        if (StringUtils.isBlank(memCard)) {
            return Result.success(BizCodeEnum.NO_LOGIN);
        }
        QkjMemberTaskInfo qkjMemberTaskInfo = qkjMemberTaskInfoDao.findByMemCard(memCard);
        if (qkjMemberTaskInfo != null) {
            data.put("totalPoints", qkjMemberTaskInfo.getMemResidualPoints());
        } else {
            data.put("totalPoints", 0);
        }

        Integer goodSize=qkjIntegralGoodsDao.findGoodMallListSize();//商品
        Integer dataSize=qkjTqcourseDao.getIndexDataAllSize();//课程
        data.put("total", goodSize+dataSize);
        Integer pageSize=(goodSize+dataSize)/size;
        if((goodSize+dataSize)%size>0){
            pageSize=pageSize+1;
        }
        data.put("pageSize", pageSize);//总分页数

        List<QkjIntegralGoods> list = new ArrayList<>();
//        List<QkjTqcourse> dataKC = new ArrayList<>();
        if(goodSize / size >= page){//如果该页数,满足商品数量
            list = getGoodsPage((page-1)*size, size);
            data.put("list", list);
            data.put("listKC", new ArrayList<>());
            return Result.success(data);
        }else{
            if( goodSize / size + 1 == page && goodSize % size != 0 ){
                list = getGoodsPage((page-1)*(goodSize % size), goodSize % size);
                data.put("list", list);
                data.put("listKC", getIndexDataPage(memCard,0,size-goodSize % size));
                return Result.success(data);
            }else{
                data.put("list", new ArrayList<>());
                data.put("listKC", getIndexDataPage(memCard,(page-(goodSize / size)-1)*size, size));
            }
            return Result.success(data);
        }
    }
*/


    @Override
    public Result findGoodMallList(String memCard,Integer page,Integer size) {
        JSONObject data = new JSONObject();
        if (StringUtils.isBlank(memCard)) {
            return Result.success(BizCodeEnum.NO_LOGIN);
        }
        QkjMemberTaskInfo qkjMemberTaskInfo = qkjMemberTaskInfoDao.findByMemCard(memCard);
        if (qkjMemberTaskInfo != null) {
            data.put("totalPoints", qkjMemberTaskInfo.getMemResidualPoints());
        } else {
            data.put("totalPoints", 0);
        }

        Integer allSize=qkjIntegralGoodsDao.findAllListSize();//所有数量
        data.put("total", allSize);//所有数量
        Integer pageSize=allSize/size;
        if((allSize)%size>0){
            pageSize=pageSize+1;
        }
        data.put("pageSize", pageSize);//总分页数

        List<Map<String,Object>> limitAll=qkjIntegralGoodsDao.findLimitAllList((page - 1) * size, size);//所有集合
        List<QkjGoodLimitDto> QkjGoodLimitList = new ArrayList<>();
        for(Map<String,Object> map:limitAll){
            QkjGoodLimitDto QkjGoodLimit=JSONArray.parseObject(JSONArray.toJSONString(map), QkjGoodLimitDto.class);
            QkjGoodLimitList.add(QkjGoodLimit);
        }
        data.put("data", QkjGoodLimitList);
        return Result.success(data);
    }

    public List<QkjIntegralGoods> getGoodsPage(Integer page,Integer size){
        List<QkjIntegralGoods> list = qkjIntegralGoodsDao.findGoodMallList(page, size);
        list.forEach(goods -> {
            goods.setIsJF("积分物品");
        });
        return list;
    }

    public List<QkjTqcourseDto> getIndexDataPage(String memCard,Integer page,Integer size){
        List<QkjTqcourse> dataKC = qkjTqcourseDao.getIndexDataAll(page,size);
        return dataKC.stream().map(item -> {
            QkjTqcourseDto qkjTqcourseDto = CopyUtil.copy(item, QkjTqcourseDto.class);
            List<SalesOrdersMain> tqcourseOrderList = orderDao.findTqcourseOrderList(memCard, 1, item.getId().intValue());
            if (tqcourseOrderList != null && !tqcourseOrderList.isEmpty()) {
                qkjTqcourseDto.setIsBuy(1);
            } else {
                qkjTqcourseDto.setIsBuy(0);
            }
            Integer purchasedMembers = 0;
            if (qkjTqcourseDto.getZq() == 2) {
                List<QkjTqcourse> listKC = qkjTqcourseDao.findTqListForZq(qkjTqcourseDto.getId().intValue());
                if (listKC != null && !listKC.isEmpty()) {
                    for (QkjTqcourse q : listKC) {
                        if (q.getPurchasedMembers() != null) {
                            purchasedMembers = purchasedMembers + q.getPurchasedMembers();
                        }
                    }
                    qkjTqcourseDto.setPurchasedMembers(purchasedMembers);
                }
            }
            qkjTqcourseDto.setIsKC("课程物品");
            return qkjTqcourseDto;
        }).collect(Collectors.toList());
    }



    @Override
    public Result findGoodDetails(String memCard, Long id) {
        QkjIntegralGoods qkjIntegralGoods = qkjIntegralGoodsDao.findById(id).get();
        return Result.success(qkjIntegralGoods);
    }

    @Override
    public Result integralLevel(String memCard) {
        //查询我的积分
        QkjMemberTaskInfo byMemCard = qkjMemberTaskInfoDao.findByMemCard(memCard);
        Integer points = byMemCard.getMemTotalPoints();
        Map<String, Integer> map = new HashMap<>();
        if (points >= 3000 && points < 6000) {
            map.put("医者", points);
        } else if (points >= 6000 && points < 9000) {
            map.put("医灵", points);
        } else if (points >= 9000 && points < 12000) {
            map.put("医尊", points);
        } else if (points >= 12000 && points < 15000) {
            map.put("医圣", points);
        } else if (points >= 15000 && points < 20000) {
            map.put("医神", points);
        } else if (points >= 20000) {
            map.put("医仙", points);
        } else {
            map.put("暂无称号", points);
        }
        return Result.success(map);
    }

//    @Override
//    public Result findUserGoodList(String memCard, Integer start, Integer size) {
//        List<QkjIntegralDetail> list = qkjIntegralDetailDao.findByMemCard(memCard, (start - 1) * size, size);
//        if (list != null && !list.isEmpty()) {
//            List<QkjIntegralDetailDto> collect = list.stream().map(item -> {
//                QkjIntegralDetailDto copy = CopyUtil.copy(item, QkjIntegralDetailDto.class);
//                if (item.getGoodsId() != null) {
//                    QkjIntegralGoods qkjIntegralGoods = qkjIntegralGoodsDao.findById(item.getGoodsId().longValue()).get();
//                    if (qkjIntegralGoods != null) {
//                        copy.setCoverImg(qkjIntegralGoods.getGoodsImg());
//                        copy.setTitle(qkjIntegralGoods.getGoodsName());
//                        copy.setPoints(qkjIntegralGoods.getGoodsNeedPoints());
//                        copy.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(item.getChangeTime().getTime()));
//                    }
//                }
//                return copy;
//            }).collect(Collectors.toList());
//            return Result.success(collect);
//        }
//        return Result.failed(BizCodeEnum.DATA_EMPTY);
//    }

    @Override
    public Result findUserGoodList(String memCard, Integer start, Integer size) {
        //查询当前用户的所有的订单
        List<SalesOrdersMain> userAllOrderList1 = orderDao.findUserAllOrderList(memCard);
        List<QkjIntegralDetailDto> integralOrder = new ArrayList<>();

        //根据用户唯一表示查找出兑换记录的数据
        List<QkjIntegralDetail> list = qkjIntegralDetailDao.findByMemCard(memCard, (start - 1) * size, size);
        //把兑换记录的数据放到list中
        if(list !=null && !list.isEmpty()){
            list.forEach(item->{
                QkjIntegralDetailDto copy = CopyUtil.copy(item, QkjIntegralDetailDto.class);
                if (item.getGoodsId() != null) {
                    QkjIntegralGoods qkjIntegralGoods = qkjIntegralGoodsDao.findById(item.getGoodsId().longValue()).get();
                    if (qkjIntegralGoods != null) {
                        copy.setCoverImg(OSSPathUtil.jointFileUrl(qkjIntegralGoods.getGoodsImg()));
                        copy.setTitle(qkjIntegralGoods.getGoodsName());
                        copy.setPoints(qkjIntegralGoods.getGoodsNeedPoints());
                        copy.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(item.getChangeTime().getTime()));
                    }
                }
                integralOrder.add(copy);
            });
        }
        //把所有的用户积分购买订单放到list中
        if(userAllOrderList1 != null && !userAllOrderList1.isEmpty()){
            userAllOrderList1.forEach(item->{
                //是否是积分购买
                if(item.getPayType()==2){
                    QkjIntegralDetailDto copy = CopyUtil.copy(item, QkjIntegralDetailDto.class);
                    //订单的类型
                    if(item.getOrderType()==1){
                        QkjTqcourse qkjTqcourse = qkjTqcourseDao.findById(Long.valueOf(item.getObjId())).get();
                        if(qkjTqcourse != null){
                            copy.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(item.getPayTime().getTime()));
                            copy.setCoverImg(qkjTqcourse.getDetailCoverImg());
                            copy.setTitle(qkjTqcourse.getTitle());
                            copy.setPoints(qkjTqcourse.getPoint());
                        }
                    }
                    if(item.getOrderType()==2){
                        //直播
                        QkjLive qkjLive = qkjLiveDao.findById(Long.parseLong(item.getObjId())).get();
                        if(qkjLive != null){
                            copy.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(item.getPayTime().getTime()));
                            copy.setCoverImg(OSSPathUtil.jointFileUrl(qkjLive.getLiveCoverImg()));
                            copy.setTitle(qkjLive.getLiveTitle());
                            copy.setPoints(qkjLive.getPoint());
                        }
                    }
                    if(item.getOrderType()==3){
                        //会议
                        QkjConference qkjConference = qkjConferenceDao.findById(Long.parseLong(item.getObjId())).get();
                        if(qkjConference != null){
                            copy.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(item.getPayTime().getTime()));
                            copy.setCoverImg(OSSPathUtil.jointFileUrl(qkjConference.getCoverImg()));
                            copy.setTitle(qkjConference.getTitle());
                            copy.setPoints(qkjConference.getPoint());
                        }
                    }
                    if(item.getOrderType()==4){
                        //课件
                        QkjCourseWare qkjCourseWare = qkjCourseWareDao.findById(Long.parseLong(item.getObjId())).get();
                        if(qkjCourseWare != null){
                            copy.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(item.getPayTime().getTime()));
                            copy.setCoverImg(qkjCourseWare.getCoverImg());
                            copy.setTitle(qkjCourseWare.getTitle());
                            copy.setPoints(qkjCourseWare.getPoint());
                        }
                    }
                    integralOrder.add(copy);
                }
            });
        }
        //按照时间排序
        List<QkjIntegralDetailDto> sortedList =integralOrder.stream().sorted(Comparator.comparing(QkjIntegralDetailDto::getTime).reversed()).collect(Collectors.toList());
        return Result.success(sortedList);
    }

    @Override
    public  Result findUserAllOrderList(String memCard){
        List<UserOderDto> userAllOrderList = new ArrayList<>();

        List<SalesOrdersMain> userAllOrderList1 = orderDao.findUserAllOrderList(memCard);
        userAllOrderList1.forEach(a -> {
            userAllOrderList.add(CopyUtil.copy(a,UserOderDto.class));
        });

        List<QkjIntegralDetail> userAllOderList2 = qkjIntegralDetailDao.findUserOder(memCard);
        userAllOderList2.forEach(a -> {
            userAllOrderList.add(CopyUtil.copy(a,UserOderDto.class));
        });

        System.out.println("--------");
        System.out.println(userAllOrderList);
        for(UserOderDto oder : userAllOrderList){
            if(oder.getCreatetime() == null && oder.getChangeTime() != null){
                oder.setCreatetime(oder.getChangeTime());
            }
        }
        List<UserOderDto> sortedList =userAllOrderList.stream().sorted(Comparator.comparing(UserOderDto::getCreatetime).reversed()).collect(Collectors.toList());

//        userAllOrderList.sort(comparing(UserOderDto::getCreatetime));
        if (sortedList != null && !sortedList.isEmpty()){
            List<UserOderDto> collect = sortedList.stream().map(item -> {
                if(item.getOrderType() == null ){
                    if (item.getGoodsId() != null) {
                        QkjIntegralGoods qkjIntegralGoods = qkjIntegralGoodsDao.findById(item.getGoodsId().longValue()).get();
                        if (qkjIntegralGoods != null) {
                            QkjIntegralDetailDto dto = CopyUtil.copy(qkjIntegralGoods,QkjIntegralDetailDto.class);
                            item.setCoverImg(qkjIntegralGoods.getGoodsImg());
                            item.setTitle(qkjIntegralGoods.getGoodsName());
                            item.setPoints(qkjIntegralGoods.getGoodsNeedPoints());
                            item.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(item.getChangeTime().getTime()));
                        }
                    }
                }else {
                    if (item.getOrderType() == 1) {
                        //精品课
                        QkjTqcourse qkjTqcourse = qkjTqcourseDao.findById(Long.parseLong(item.getObjId())).get();
                        QkjTqcourseDto qkjTqcourseDto = CopyUtil.copy(qkjTqcourse, QkjTqcourseDto.class);
                        qkjTqcourseDto.setStudyNumTOW(qkjTqcourse.getPurchasedMembers()+qkjTqcourse.getStudyNum());
                        Integer purchasedMembers = 0;
                        if (qkjTqcourseDto.getZq() == 2) {
                            List<QkjTqcourse> list = qkjTqcourseDao.findTqListForZq(qkjTqcourseDto.getId().intValue());
                            if (list != null && !list.isEmpty()) {
                                for (QkjTqcourse q : list) {
                                    if (q.getPurchasedMembers() == null) {
                                        q.setPurchasedMembers(0);
                                    }
                                    purchasedMembers = purchasedMembers + q.getPurchasedMembers() +q.getStudyNum();
                                }
                                qkjTqcourseDto.setTotalClassHours(list.size());
                                qkjTqcourseDto.setPurchasedMembers(purchasedMembers);
                                qkjTqcourseDto.setStudyNumTOW(purchasedMembers);
                            }
                        }
                        qkjTqcourseDto.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(qkjTqcourse.getCreateTime()));
                        item.setStatus(qkjTqcourseDto.getStatus());
                        item.setQkjTqcourse(qkjTqcourseDto);
                    }
                    if (item.getOrderType() == 2) {
                        //直播
                        QkjLive qkjLive = qkjLiveDao.findById(Long.parseLong(item.getObjId())).get();
                        QkjLiveDto copy = CopyUtil.copy(qkjLive, QkjLiveDto.class);
                        copy.setLiveManTime(qkjLive.getJoinMembers() + qkjLive.getPurchasedMembers());
                        if(qkjLive.getLiveType() == 2){
                            //统计系列直播学习人数
                            List<QkjLive> sonLives = qkjLiveDao.findSonList(qkjLive.getId().intValue(), 0, 100);
                            int joinMembers = 0;
                            for(QkjLive nom : sonLives){
                                joinMembers = joinMembers + nom.getJoinMembers() + nom.getPurchasedMembers();
                            }
                            copy.setLiveSonCount(sonLives.size());
                            copy.setLiveManTime(joinMembers);
                        }
                        copy.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(qkjLive.getLiveBeginTime().getTime()));
                        item.setStatus(copy.getStatus());//什么意思
                        item.setQkjLive(copy);
                    }
                    if (item.getOrderType() == 3) {
                        //会议
                        Optional<QkjConference> byId = qkjConferenceDao.findById(Long.parseLong(item.getObjId()));
                        if (byId != null && byId.isPresent()) {
                            QkjConference qkjConference = byId.get();
                            QkjConferenceDTO dto = CopyUtil.copy(qkjConference, QkjConferenceDTO.class);
                            dto.setTimeStr(DateFormater.formatDate(qkjConference.getBigenTime(), "yyyy.MM.dd") + "-" + DateFormater.formatDate(qkjConference.getEndTime(), "MM.dd"));
                            item.setStatus(dto.getStatus());
                            item.setQkjConference(dto);
                        }
                    }
                    if (item.getOrderType() == 4) {
                        //课件
                        Optional<QkjCourseWare> byId = qkjCourseWareDao.findById(Long.parseLong(item.getObjId()));
                        if (byId != null && byId.isPresent()) {
                            QkjCourseWare qkjCourseWare = byId.get();
                            item.setStatus(qkjCourseWare.getStatus());
                            item.setQkjCourseWare(qkjCourseWare);
                        }
                    }
                }
                return item;
            }).collect(Collectors.toList());
            return Result.success(collect);
        }
        return Result.failed(BizCodeEnum.DATA_EMPTY);
    }

    @Override
    public Result findUserOrderList(String memCard, Integer start, Integer size, Integer type) {
        List<SalesOrdersMain> myOrderListAll = new ArrayList<>();
        if (type == -1) {
            myOrderListAll = orderDao.findMyOrderListAll(memCard, (start - 1) * size, size);
        } else {
            myOrderListAll = orderDao.findMyOrderListAll(memCard,(start - 1) * size, size, type);
        }
        if (myOrderListAll != null && !myOrderListAll.isEmpty()) {
            List<SalesOrdersMainDto> collect = myOrderListAll.stream().map(item -> {
                SalesOrdersMainDto salesOrdersMainDto = CopyUtil.copy(item, SalesOrdersMainDto.class);
                if (item.getOrderType() == 1) {
                    //精品课
                    QkjTqcourse qkjTqcourse = qkjTqcourseDao.findById(Long.parseLong(item.getObjId())).get();
                    QkjTqcourseDto qkjTqcourseDto = CopyUtil.copy(qkjTqcourse, QkjTqcourseDto.class);
                    qkjTqcourseDto.setStudyNumTOW(qkjTqcourse.getPurchasedMembers()+qkjTqcourse.getStudyNum());
                    Integer purchasedMembers = 0;
                    if (qkjTqcourseDto.getZq() == 2) {
                        List<QkjTqcourse> list = qkjTqcourseDao.findTqListForZq(qkjTqcourseDto.getId().intValue());
                        if (list != null && !list.isEmpty()) {
                            for (QkjTqcourse q : list) {
                                if (q.getPurchasedMembers() == null) {
                                    q.setPurchasedMembers(0);
                                }
                                purchasedMembers = purchasedMembers + q.getPurchasedMembers()+q.getStudyNum();
                            }
                            qkjTqcourseDto.setTotalClassHours(list.size());
                            qkjTqcourseDto.setPurchasedMembers(purchasedMembers);
                            qkjTqcourseDto.setStudyNumTOW(purchasedMembers);
                        }
                    }
                    qkjTqcourseDto.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(qkjTqcourse.getCreateTime()));
                    salesOrdersMainDto.setStatus(qkjTqcourseDto.getStatus());
                    salesOrdersMainDto.setQkjTqcourse(qkjTqcourseDto);
                }
                if (item.getOrderType() == 2) {
                    //直播
                    QkjLive qkjLive = qkjLiveDao.findById(Long.parseLong(item.getObjId())).get();
                    QkjLiveDto copy = CopyUtil.copy(qkjLive, QkjLiveDto.class);
                    copy.setLiveManTime(qkjLive.getJoinMembers() + qkjLive.getPurchasedMembers());
                    if(qkjLive.getLiveType() == 2){
                        //统计系列直播学习人数
                        List<QkjLive> sonLives = qkjLiveDao.findSonList(qkjLive.getId().intValue(), 0, 100);
                        int joinMembers = 0;
                        for(QkjLive nom : sonLives){
                            joinMembers = joinMembers + nom.getJoinMembers() + nom.getPurchasedMembers();
                        }
                        copy.setLiveSonCount(sonLives.size());
                        copy.setLiveManTime(joinMembers);
                    }
                    copy.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(qkjLive.getLiveBeginTime().getTime()));
                    salesOrdersMainDto.setStatus(copy.getStatus());//什么意思
                    salesOrdersMainDto.setQkjLive(copy);
                }
                if (item.getOrderType() == 3) {
                    //会议
                    Optional<QkjConference> byId = qkjConferenceDao.findById(Long.parseLong(item.getObjId()));
                    if (byId != null && byId.isPresent()) {
                        QkjConference qkjConference = byId.get();
                        QkjConferenceDTO dto = CopyUtil.copy(qkjConference, QkjConferenceDTO.class);
                        dto.setTimeStr(DateFormater.formatDate(qkjConference.getBigenTime(), "yyyy.MM.dd") + "-" + DateFormater.formatDate(qkjConference.getEndTime(), "MM.dd"));
                        salesOrdersMainDto.setStatus(dto.getStatus());
                        salesOrdersMainDto.setQkjConference(dto);
                    }
                }
                if (item.getOrderType() == 4) {
                    //课件
                    Optional<QkjCourseWare> byId = qkjCourseWareDao.findById(Long.parseLong(item.getObjId()));
                    if (byId != null && byId.isPresent()) {
                        QkjCourseWare qkjCourseWare = byId.get();
                        salesOrdersMainDto.setStatus(qkjCourseWare.getStatus());
                        salesOrdersMainDto.setQkjCourseWare(qkjCourseWare);
                    }

                }
                return salesOrdersMainDto;
            }).collect(Collectors.toList());
            return Result.success(collect);
        }
        return Result.failed(BizCodeEnum.DATA_EMPTY);
    }

    @Override
    public Result findUserCollectionList(String memCard, Integer start, Integer size, Integer type) {
        List<SalesCollectionMain> collectionMains = new ArrayList<>();
        if (type == -1) {
            collectionMains = collectionDao.findMyCollectionListAll(memCard, (start - 1) * size, size);
        } else {
            collectionMains = collectionDao.findMyCollectionListAllByType(memCard, type, (start - 1) * size, size);
        }
        if (collectionMains != null && !collectionMains.isEmpty()) {
            List<SalesOrdersMainDto> collect = collectionMains.stream().map(item -> {
                SalesOrdersMainDto salesOrdersMainDto = new SalesOrdersMainDto();
                if (item.getType() == 1) {
                    salesOrdersMainDto.setOrderType(1);
                    //精品课
                    QkjTqcourse qkjTqcourse = qkjTqcourseDao.findById(Long.parseLong(item.getTypeId())).get();
                    QkjTqcourseDto qkjTqcourseDto = CopyUtil.copy(qkjTqcourse, QkjTqcourseDto.class);
                    Integer purchasedMembers = 0;
                    if (qkjTqcourseDto.getZq() == 2) {
                        List<QkjTqcourse> list = qkjTqcourseDao.findTqListForZq(qkjTqcourseDto.getId().intValue());
                        if (list != null && !list.isEmpty()) {
                            for (QkjTqcourse q : list) {
                                purchasedMembers = purchasedMembers + q.getPurchasedMembers();
                            }
                            qkjTqcourseDto.setPurchasedMembers(purchasedMembers);
                        }
                    }
                    qkjTqcourseDto.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(qkjTqcourse.getCreateTime()));
                    salesOrdersMainDto.setQkjTqcourse(qkjTqcourseDto);
                }
                if (item.getType() == 2) {
                    salesOrdersMainDto.setOrderType(2);
                    //直播
                    QkjLive qkjLive = qkjLiveDao.findById(Long.parseLong(item.getTypeId())).get();
                    QkjLiveDto copy = CopyUtil.copy(qkjLive, QkjLiveDto.class);
                    copy.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(qkjLive.getLiveBeginTime().getTime()));
                    salesOrdersMainDto.setQkjLive(copy);
                }
                if (item.getType() == 3) {
                    salesOrdersMainDto.setOrderType(3);
                    //会议
                    Optional<QkjConference> byId = qkjConferenceDao.findById(Long.parseLong(item.getTypeId()));
                    if (byId != null && byId.isPresent()) {
                        QkjConference qkjConference = byId.get();
                        QkjConferenceDTO dto = CopyUtil.copy(qkjConference, QkjConferenceDTO.class);
                        dto.setTimeStr(DateFormater.formatDate(qkjConference.getBigenTime(), "yyyy.MM.dd") + "-" + DateFormater.formatDate(qkjConference.getEndTime(), "MM.dd"));
                        salesOrdersMainDto.setQkjConference(dto);
                    }
                }
                return salesOrdersMainDto;
            }).collect(Collectors.toList());
            return Result.success(collect);
        }
        return null;
    }

    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public Result saveCollectionWeb(String memCard, String typeId, Integer type, Integer isDel, Integer id) {
        SalesCollectionMain salesCollectionMain = new SalesCollectionMain();
        salesCollectionMain.setCollectionTime(Calendar.getInstance());
        salesCollectionMain.setMemCard(memCard);
        salesCollectionMain.setType(type);
        salesCollectionMain.setTypeId(typeId);
        if (isDel == 2) {
            collectionDao.save(salesCollectionMain);
        } else {
            Optional<SalesCollectionMain> first = collectionDao.getCollectionInfo(memCard, typeId, type).stream().findFirst();
            first.ifPresent(f -> collectionDao.delete(f));
        }
        return Result.success(BizCodeEnum.SUCCESS);
    }


    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public Result saveUserInfoWithSmV2(String memCard, String userName, String card, String unitName, String address, String addressXx, String experience, String sex, String email, Integer documentType, String documentNumber, Integer degree, Integer bachelorDegree, Integer occupationType, Integer unitArea, String unitAddress, String specialization
            ,String department,String province, String city, String businessLicense, Integer post) {
        log.info("saveUserInfoWithSmV2 join memCard:{} card:{} businessLicense:{}", memCard, card, businessLicense);
        try {
            // 身份证号码需要加密
            String encryptedCard = identificationNumberEncryptor.encrypt(card);
            QkjMemberPersonalAuth list = qkjMemberPersonalAuthDao.checkCard(encryptedCard);
            if (list != null && !list.getMemCard().equals(memCard)) {
                return Result.failed(BizCodeEnum.CRAD_USE);
            }

            QkjCertificatePhysicians listYs = qkjCertificatePhysiciansDao.findByNum(businessLicense);
            if (listYs != null && !listYs.getMemCard().equals(memCard)) {
                return Result.failed(BizCodeEnum.BUS_USE);
            }

            QkjMemberPersonalAuth qkjMemberPersonalAuth = qkjMemberPersonalAuthDao.findByMemCard(memCard);
            Boolean isNew = Objects.isNull(qkjMemberPersonalAuth) || StringUtils.isBlank(qkjMemberPersonalAuth.getMemIdentityId());
            if (qkjMemberPersonalAuth == null) {
                qkjMemberPersonalAuth = new QkjMemberPersonalAuth();
            }
            qkjMemberPersonalAuth.setAuthTime(new Date());
            qkjMemberPersonalAuth.setDetailedAddress(addressXx);
            if(StringUtils.isNotBlank(address)){
                qkjMemberPersonalAuth.setMemAddr(address);
            }
            qkjMemberPersonalAuth.setStatus(1);
            if(StringUtils.isNotBlank(experience)){
                qkjMemberPersonalAuth.setMemExp(experience);
            }
            qkjMemberPersonalAuth.setMemCard(memCard);
            if(StringUtils.isNotBlank(encryptedCard)){
                qkjMemberPersonalAuth.setMemIdentityId(encryptedCard);
            }
            qkjMemberPersonalAuth.setMemSex(Integer.parseInt(sex));
            qkjMemberPersonalAuth.setMemRealName(userName);
            qkjMemberPersonalAuth.setUnitName(unitName);
            //new save
            qkjMemberPersonalAuth.setEmail(email);
            qkjMemberPersonalAuth.setDocumentType(documentType);
            qkjMemberPersonalAuth.setDocumentNumber(documentNumber);
            qkjMemberPersonalAuth.setDegree(degree);
            qkjMemberPersonalAuth.setBachelorDegree(bachelorDegree);
            qkjMemberPersonalAuth.setOccupationType(occupationType);
            qkjMemberPersonalAuth.setUnitArea(unitArea);
            qkjMemberPersonalAuth.setUnitAddress(unitAddress);
            qkjMemberPersonalAuth.setSpecialization(specialization);
            if (StringUtils.isNotBlank(province)) {
                qkjMemberPersonalAuth.setProvince(province);
            }
            if (StringUtils.isNotBlank(city)) {
                qkjMemberPersonalAuth.setCity(city);
            }
            if(StringUtils.isNotBlank(department)){
                qkjMemberPersonalAuth.setDepartment(department);
            }

            qkjMemberPersonalAuthDao.save(qkjMemberPersonalAuth);

            QkjMember member = memberDao.findByMemCard(memCard);
            if (member != null) {
                member.setSmrzFlag(1);
                memberDao.save(member);
            }
            if (isNew) {
                qkjTaskService.dailyCheckIn(memCard, 22, TaskConsts.TASK_22_POINTS);
            }

            //增加医师认证
            QkjCertificatePhysicians qkjCertificatePhysicians = qkjCertificatePhysiciansDao.findByMemCard(memCard);
            boolean isNewYs = false;
            if (qkjCertificatePhysicians == null) {
                isNewYs = true;
                qkjCertificatePhysicians = new QkjCertificatePhysicians();
            }
            qkjCertificatePhysicians.setCreateTime(new Date());
            qkjCertificatePhysicians.setMemCard(memCard);
            qkjCertificatePhysicians.setAuditingStatus(0);
            qkjCertificatePhysicians.setNum(businessLicense);
            qkjCertificatePhysicians.setPost(post);
            qkjCertificatePhysiciansDao.save(qkjCertificatePhysicians);

            if (member != null) {
                member.setYsrzFlag(1);
                memberDao.save(member);
            }
            //第一次医师认证增加积分
            if (isNewYs) {
                qkjTaskService.dailyCheckIn(memCard, 25, TaskConsts.TASK_25_POINTS);
            }
            //保存成功返回给前端增加的具体积分数
            int points = 0;
            if(isNew && isNewYs){
                points = TaskConsts.TASK_22_POINTS + TaskConsts.TASK_25_POINTS;
            }else if(isNewYs){
                points = TaskConsts.TASK_25_POINTS;
            }else if(isNew){
                points = TaskConsts.TASK_22_POINTS;
            }
            Map<String, Integer> resultMap = Maps.newHashMap();
            resultMap.put("points", points);
            return Result.success(resultMap);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Result.failed(BizCodeEnum.FAILED);
        }
    }

    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public Result saveUserInfoWithSm(String memCard, String userName, String card, String unitName, String address, String addressXx, String experience, String sex, String email, Integer documentType, String documentNumber, Integer degree, Integer bachelorDegree, Integer occupationType, Integer unitArea, String unitAddress, String specialization) {
        log.info("saveUserInfoWithSm memCard:{} userName:{}", memCard, userName);
        try {
            // 身份证号码需要加密
            String encryptedCard = identificationNumberEncryptor.encrypt(card);
            QkjMemberPersonalAuth list = qkjMemberPersonalAuthDao.checkCard(encryptedCard);
            if (list != null && !list.getMemCard().equals(memCard)) {
                return Result.failed(BizCodeEnum.CRAD_USE);
            }
            QkjMemberPersonalAuth qkjMemberPersonalAuth = qkjMemberPersonalAuthDao.findByMemCard(memCard);
            //有可能是完成了欧佳龙医师认证，已经有部分实名认证的信息了但是没有填写身份证号，不算完成了实名认证没有加积分需要单独处理
            Boolean isNew = Objects.isNull(qkjMemberPersonalAuth) || StringUtils.isBlank(qkjMemberPersonalAuth.getMemIdentityId());
            if (qkjMemberPersonalAuth == null) {
                qkjMemberPersonalAuth = new QkjMemberPersonalAuth();
            }
            qkjMemberPersonalAuth.setAuthTime(new Date());
            qkjMemberPersonalAuth.setDetailedAddress(addressXx);
            qkjMemberPersonalAuth.setMemAddr(address);
            qkjMemberPersonalAuth.setStatus(1);
            qkjMemberPersonalAuth.setMemExp(experience);
            qkjMemberPersonalAuth.setMemCard(memCard);
            qkjMemberPersonalAuth.setMemIdentityId(encryptedCard);
            qkjMemberPersonalAuth.setMemSex(Integer.parseInt(sex));
            qkjMemberPersonalAuth.setMemRealName(userName);
            qkjMemberPersonalAuth.setUnitName(unitName);
            //new save
            qkjMemberPersonalAuth.setEmail(email);
            qkjMemberPersonalAuth.setDocumentType(documentType);
            qkjMemberPersonalAuth.setDocumentNumber(documentNumber);
            qkjMemberPersonalAuth.setDegree(degree);
            qkjMemberPersonalAuth.setBachelorDegree(bachelorDegree);
            qkjMemberPersonalAuth.setOccupationType(occupationType);
            qkjMemberPersonalAuth.setUnitArea(unitArea);
            qkjMemberPersonalAuth.setUnitAddress(unitAddress);
            qkjMemberPersonalAuth.setSpecialization(specialization);

            qkjMemberPersonalAuthDao.save(qkjMemberPersonalAuth);

            QkjMember member = memberDao.findByMemCard(memCard);
            if (member != null) {
                member.setSmrzFlag(1);
                memberDao.save(member);
            }
            if (isNew) {
                qkjTaskService.dailyCheckIn(memCard, 22, TaskConsts.TASK_22_POINTS);
            }//保存成功返回给前端增加的具体积分数
            int points = 0;
            if(isNew){
                points = TaskConsts.TASK_22_POINTS;
            }
            Map<String, Integer> resultMap = Maps.newHashMap();
            resultMap.put("points", points);
            return Result.success(resultMap);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Result.failed(BizCodeEnum.FAILED);
        }
    }

    @Override
    public Result findUserAttestInfo(String memCard) {

        Map<String, Object> map  = Maps.newHashMap();
        //查询医师认证的信息
        QkjCertificatePhysicians physicians = qkjCertificatePhysiciansDao.findByMemCard(memCard);

        if(Objects.nonNull(physicians)){
            map.put("physicians", physicians);
        }
        //查询实名认证的信息
        //解密身份证号
        QkjMemberPersonalAuth memberPersonalAuth = qkjMemberPersonalAuthDao.findByMemCard(memCard);
        QkjMemberPersonalAuthDto qkjMemberDto = new QkjMemberPersonalAuthDto();
        if (Objects.nonNull(memberPersonalAuth)) {
            qkjMemberDto = CopyUtil.copy(memberPersonalAuth, QkjMemberPersonalAuthDto.class);

            QkjMemberPersonalAuthDto conver = conver(qkjMemberDto);
            map.put("personalAuth", conver);
        }
        return Result.success(map);
    }

    private QkjMemberPersonalAuthDto conver(QkjMemberPersonalAuthDto qkjMemberDto) {
        String decrypt = identificationNumberEncryptor.decrypt(qkjMemberDto.getMemIdentityId());
        //qkjMemberDto.setMemIdentityId(StringUtil.reNo(decrypt));
        qkjMemberDto.setMemIdentityId(decrypt);
        if (StringUtils.isNotBlank(qkjMemberDto.getMemExp()) && qkjMemberDto.getMemExp().contains("-")) {
            String memExp = Strings.EMPTY;
            switch (qkjMemberDto.getMemExp()) {
                case "1-3":
                    memExp = "1";
                    break;
                case "3-5":
                    memExp = "2";
                    break;
                case "5-10":
                    memExp = "3";
                    break;
                case "10-15":
                    memExp = "4";
                    break;
                case "-1":
                    break;

            }
            qkjMemberDto.setMemExp(memExp);
        }

        if (StringUtils.isNotBlank(qkjMemberDto.getProvince() ) ) {
            try {
                boolean result=qkjMemberDto.getProvince().matches("[0-9]+");
                if(!result){
                    Integer provinceId = regionDao.findIdByName(qkjMemberDto.getProvince());
                    qkjMemberDto.setProvince(String.valueOf(provinceId));
                }
            }catch (Exception e){
                log.info("QkjMemberPersonalAuthDto provinceId e:{}", e.getMessage());
            }
        }

        if (StringUtils.isNotBlank(qkjMemberDto.getCity() ) ) {
            try {
                boolean result=qkjMemberDto.getCity().matches("[0-9]+");
                if(!result){
                    Integer cityId = regionDao.findIdByName(qkjMemberDto.getCity());
                    qkjMemberDto.setCity(String.valueOf(cityId));
                }
            }catch (Exception e){
                log.info("QkjMemberPersonalAuthDto cityId e:{}", e.getMessage());
            }
        }

        return qkjMemberDto;
    }

    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public Result saveUserInfoWithYs(String memCard, String businessLicense, Integer professional, Integer professionalTwo) {
        try {
            QkjCertificatePhysicians list = qkjCertificatePhysiciansDao.findByNum(businessLicense);
            if (list != null && !list.getMemCard().equals(memCard)) {
                return Result.failed(BizCodeEnum.BUS_USE);
            }
            QkjCertificatePhysicians qkjCertificatePhysicians = qkjCertificatePhysiciansDao.findByMemCard(memCard);
            Boolean isNew = false;
            if (qkjCertificatePhysicians == null) {
                isNew = true;
                qkjCertificatePhysicians = new QkjCertificatePhysicians();
            }
            qkjCertificatePhysicians.setCreateTime(new Date());
            qkjCertificatePhysicians.setMemCard(memCard);
            qkjCertificatePhysicians.setAuditingStatus(0);
            qkjCertificatePhysicians.setNum(businessLicense);
            qkjCertificatePhysicians.setProfessional(professional);
            qkjCertificatePhysicians.setProfessionalTwo(professionalTwo);
            qkjCertificatePhysiciansDao.save(qkjCertificatePhysicians);

            QkjMember member = memberDao.findByMemCard(memCard);
            if (member != null) {
                member.setYsrzFlag(1);
                memberDao.save(member);
            }
            if (isNew) {
                qkjTaskService.dailyCheckIn(memCard, 25, 500);
            }
            return Result.success(BizCodeEnum.SUCCESS);
        } catch (Exception e) {
            return Result.failed(BizCodeEnum.FAILED);
        }

    }


    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public Result saveUserInfoWithYsNew(String memCard, String businessLicense, Integer professional, Integer professionalTwo, Integer post) {
        log.info("saveUserInfoWithYsNew memCard:{} businessLicense:{}", memCard, businessLicense);
        try {
            QkjCertificatePhysicians list = qkjCertificatePhysiciansDao.findByNum(businessLicense);
            if (list != null && !list.getMemCard().equals(memCard)) {
                return Result.failed(BizCodeEnum.BUS_USE);
            }
            QkjCertificatePhysicians qkjCertificatePhysicians = qkjCertificatePhysiciansDao.findByMemCard(memCard);
            Boolean isNew = false;
            if (qkjCertificatePhysicians == null) {
                isNew = true;
                qkjCertificatePhysicians = new QkjCertificatePhysicians();
            }
            qkjCertificatePhysicians.setCreateTime(new Date());
            qkjCertificatePhysicians.setMemCard(memCard);
            qkjCertificatePhysicians.setAuditingStatus(0);
            qkjCertificatePhysicians.setNum(businessLicense);
            qkjCertificatePhysicians.setProfessional(professional);
            qkjCertificatePhysicians.setProfessionalTwo(professionalTwo);
            qkjCertificatePhysicians.setPost(post);
            qkjCertificatePhysiciansDao.save(qkjCertificatePhysicians);

            QkjMember member = memberDao.findByMemCard(memCard);
            if (member != null) {
                member.setYsrzFlag(1);
                memberDao.save(member);
            }
            if (isNew) {
                qkjTaskService.dailyCheckIn(memCard, 25, TaskConsts.TASK_25_POINTS);
            }
            //保存成功返回给前端增加的具体积分数
            int points = 0;
            if(isNew){
                points = TaskConsts.TASK_25_POINTS;
            }
            Map<String, Integer> resultMap = Maps.newHashMap();
            resultMap.put("points", points);
            return Result.success(resultMap);
        } catch (Exception e) {
            return Result.failed(BizCodeEnum.FAILED);
        }

    }

    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public Result saveUserInfoWithYsNewV2(String memCard, String userName, String unitName,  String sex,String department,
                                          String province, String city, String businessLicense, Integer professional, Integer professionalTwo, Integer post, boolean needCheck) {
        log.info("saveUserInfoWithYsNewV2 join memCard:{} businessLicense:{} professional:{} professionalTwo:{} post:{} needCheck:{}", memCard, businessLicense, professional, professionalTwo, post, needCheck);
        try {
            if (needCheck) {
                QkjCertificatePhysicians list = qkjCertificatePhysiciansDao.findByNum(businessLicense);
                if (list != null && !list.getMemCard().equals(memCard)) {
                    return Result.failed(BizCodeEnum.BUS_USE);
                }
            }
            if(StringUtils.isBlank(businessLicense)){
                businessLicense = null;
            }
            QkjCertificatePhysicians qkjCertificatePhysicians = qkjCertificatePhysiciansDao.findByMemCard(memCard);
            Boolean isNew = false;
            if (qkjCertificatePhysicians == null) {
                isNew = true;
                qkjCertificatePhysicians = new QkjCertificatePhysicians();
            }
            qkjCertificatePhysicians.setCreateTime(new Date());
            qkjCertificatePhysicians.setMemCard(memCard);
            qkjCertificatePhysicians.setAuditingStatus(0);
            qkjCertificatePhysicians.setNum(businessLicense);
            qkjCertificatePhysicians.setProfessional(professional);
            qkjCertificatePhysicians.setProfessionalTwo(professionalTwo);
            qkjCertificatePhysicians.setPost(post);
            qkjCertificatePhysiciansDao.save(qkjCertificatePhysicians);

            QkjMember member = memberDao.findByMemCard(memCard);
            if (member != null) {
                member.setYsrzFlag(1);
                memberDao.save(member);
            }
            if (isNew) {
                qkjTaskService.dailyCheckIn(memCard, 25, TaskConsts.TASK_25_POINTS);
            }

            //实名认证
            QkjMemberPersonalAuth qkjMemberPersonalAuth = qkjMemberPersonalAuthDao.findByMemCard(memCard);
            if (qkjMemberPersonalAuth == null) {
                qkjMemberPersonalAuth = new QkjMemberPersonalAuth();
            }

            qkjMemberPersonalAuth.setMemCard(memCard);
            qkjMemberPersonalAuth.setMemRealName(userName);
            if(StringUtils.isNotBlank(sex)){
                qkjMemberPersonalAuth.setMemSex(Integer.parseInt(sex));
            }
            if(StringUtils.isNotBlank(unitName)){
                qkjMemberPersonalAuth.setUnitName(unitName);
            }
            if(StringUtils.isNotBlank(department)){
                qkjMemberPersonalAuth.setDepartment(department);
            }
            //new save
            if (StringUtils.isNotBlank(province)) {
                qkjMemberPersonalAuth.setProvince(province);
            }
            if (StringUtils.isNotBlank(city)) {
                qkjMemberPersonalAuth.setCity(city);
            }


            qkjMemberPersonalAuth.setAuthTime(new Date());//非必填
            qkjMemberPersonalAuth.setStatus(1);
            qkjMemberPersonalAuthDao.save(qkjMemberPersonalAuth);
            //保存成功返回给前端增加的具体积分数
            int points = 0;
            if(isNew){
                points = TaskConsts.TASK_25_POINTS;
            }
            Map<String, Integer> resultMap = Maps.newHashMap();
            resultMap.put("points", points);
            return Result.success(resultMap);
        } catch (Exception e) {
            return Result.failed(BizCodeEnum.FAILED);
        }

    }

    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public Result changeUserHeader(String key, String memCard) {
        QkjMember byMemCard = memberDao.findByMemCard(memCard);
        if (byMemCard != null) {
            byMemCard.setMemHeadimg("https://files.qkyxzx.com/" + key);
            memberDao.save(byMemCard);
            return Result.success(BizCodeEnum.SUCCESS);
        }
        return Result.success(BizCodeEnum.MEM_CARD_ERROR);
    }

    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public Result UpdateUserInfo(String memCard, String userName, String phone, String headerImg) {
        if (StringUtils.isNotBlank(memCard)) {
            QkjMember qkjMember = memberDao.findByMemCard(memCard);
            if (StringUtils.isNotBlank(userName)) {
                qkjMember.setMemNickname(userName);
            }
            if (StringUtils.isNotBlank(phone)) {
                qkjMember.setMemMobile(phone);
            }
            if (StringUtils.isNotBlank(headerImg)) {
                qkjMember.setMemHeadimg(headerImg);
            }
            memberDao.save(qkjMember);
            return Result.success(BizCodeEnum.SUCCESS);
        }
        return Result.failed(BizCodeEnum.NO_LOGIN);
    }

    @Override
    public Result findUserStudyRecord(String memCard, Integer start, Integer size) {
        if (StringUtils.isNotBlank(memCard)) {
            List<QkjVedioPlayRecord> list = qkjVedioPlayRecordDao.findUserStudyList(memCard, (start - 1) * size, size);
            if (list != null && !list.isEmpty()) {
                List<QkjVedioPlayRecordDto> collect = list.stream().map(item -> {
                    QkjVedioPlayRecordDto copy = CopyUtil.copy(item, QkjVedioPlayRecordDto.class);
                    if (item.getObjType() == 7) {
                        //课程
                        Optional<QkjTqcourse> byId = qkjTqcourseDao.findById(item.getObjId().longValue());
                        if (byId.isPresent()) {
                            QkjTqcourse qkjTqcourse = byId.get();
///                         QkjVideoPlayLog qkjVideoPlayLog = qkjVideoPlayLogDao.findCourseLogList(memCard,qkjTqcourse.getId());
                            List<QkjVedioPlayRecord> qkjVedioPlayRecord = qkjVedioPlayRecordDao.findPlayTimeByMemCardAndObjIdAndObjTypeAndPobjId(memCard, 1, qkjTqcourse.getId().intValue());
                            Integer PlayTime = 0;
                            for (int i = 0; i < qkjVedioPlayRecord.size(); i++) {
                                QkjVedioPlayRecord qkjVedioPlayRecord1 = qkjVedioPlayRecord.get(i);
                                PlayTime = PlayTime + qkjVedioPlayRecord1.getPlayTime();
                            }
                            qkjTqcourse.setLearnTime(PlayTime / 1000 / 60);
                            copy.setQkjTqcourse(qkjTqcourse);
                        }
                    } else {
                        //直播
                        QkjLive byLiveId = qkjLiveDao.findById(item.getObjId().longValue()).get();
///                        QkjVideoPlayLog qkjVideoPlayLog = qkjVideoPlayLogDao.findLiveLogList(memCard,item.getObjId().longValue());
                        List<QkjVedioPlayRecordLog> qkjVedioPlayRecordLogs = qkjVedioPlayRecordLogDao.findAllByMemCardAndObjIdAndObjTypeAndObjType(memCard,  2, byLiveId.getId().intValue(),2);
                        int playTime = 0;
                        //如果没有回看就设置成直播的观看时间
                        if(qkjVedioPlayRecordLogs.size()==0){
                            List<QkjVedioPlayRecordLog> qkjVedioPlayRecordLog = qkjVedioPlayRecordLogDao.findAllByMemCardAndObjIdAndObjTypeAndObjType(memCard, 2, byLiveId.getId().intValue(), 1);
                            for (int i = 0; i < qkjVedioPlayRecordLog.size(); i++) {
                                QkjVedioPlayRecordLog qkjVedioPlayRecordLog1 = qkjVedioPlayRecordLog.get(i);
                                playTime = playTime + qkjVedioPlayRecordLog1.getLearnTime();
                            }
                        }else{
                            for (int i = 0; i < qkjVedioPlayRecordLogs.size(); i++) {
                                QkjVedioPlayRecordLog qkjVedioPlayRecordLog1 = qkjVedioPlayRecordLogs.get(i);
                                playTime = playTime + qkjVedioPlayRecordLog1.getLearnTime();
                            }
                        }
                        byLiveId.setLearnTime(playTime / 1000 / 60);
                        copy.setQkjLive(byLiveId);
                    }
                    return copy;
                }).collect(Collectors.toList());
                return Result.success(collect);
            }
        }
        return Result.failed(BizCodeEnum.NO_LOGIN);
    }


    @Override
    public Result findUserStudyRecordWeb(String memCard, Integer start, Integer size) {
        if (StringUtils.isNotBlank(memCard)) {
            List<QkjVedioPlayRecord> list = qkjVedioPlayRecordDao.findUserStudyList(memCard, (start - 1) * size, 999);
            if (list != null && !list.isEmpty()) {
                List<QkjVedioPlayRecordDto> collect = list.stream().map(item -> {
                    QkjVedioPlayRecordDto copy = CopyUtil.copy(item, QkjVedioPlayRecordDto.class);
                    if (item.getObjType() == 7) {
                        //课程
                        Optional<QkjTqcourse> byId = qkjTqcourseDao.findById(item.getObjId().longValue());
                        if (byId.isPresent()) {
                            QkjTqcourse qkjTqcourse = byId.get();
///                         QkjVideoPlayLog qkjVideoPlayLog = qkjVideoPlayLogDao.findCourseLogList(memCard,qkjTqcourse.getId());
                            List<QkjVedioPlayRecord> qkjVedioPlayRecord = qkjVedioPlayRecordDao.findPlayTimeByMemCardAndObjIdAndObjTypeAndPobjId(memCard, 1, qkjTqcourse.getId().intValue());
                            Integer PlayTime = 0;
                            for (int i = 0; i < qkjVedioPlayRecord.size(); i++) {
                                QkjVedioPlayRecord qkjVedioPlayRecord1 = qkjVedioPlayRecord.get(i);
                                PlayTime = PlayTime + qkjVedioPlayRecord1.getPlayTime();
                            }
                            qkjTqcourse.setLearnTime(PlayTime / 1000 / 60);
                            copy.setQkjTqcourse(qkjTqcourse);
                        }
                    } else {
                        //直播
                        QkjLive byLiveId = qkjLiveDao.findById(item.getObjId().longValue()).get();
///                     QkjVideoPlayLog qkjVideoPlayLog = qkjVideoPlayLogDao.findLiveLogList(memCard,item.getObjId().longValue());
                        List<QkjVedioPlayRecordLog> qkjVedioPlayRecordLogs = qkjVedioPlayRecordLogDao.findAllByMemCardAndObjIdAndObjTypeAndObjType(memCard,  2, byLiveId.getId().intValue(),2);
                        int playTime = 0;
                        //如果没有回看就设置成直播的观看时间
                        if(qkjVedioPlayRecordLogs.size()==0){
                            List<QkjVedioPlayRecordLog> qkjVedioPlayRecordLog = qkjVedioPlayRecordLogDao.findAllByMemCardAndObjIdAndObjTypeAndObjType(memCard, 2, byLiveId.getId().intValue(), 1);
                            for (int i = 0; i < qkjVedioPlayRecordLog.size(); i++) {
                                QkjVedioPlayRecordLog qkjVedioPlayRecordLog1 = qkjVedioPlayRecordLog.get(i);
                                playTime = playTime + qkjVedioPlayRecordLog1.getLearnTime();
                            }
                        }else{
                            for (int i = 0; i < qkjVedioPlayRecordLogs.size(); i++) {
                                QkjVedioPlayRecordLog qkjVedioPlayRecordLog1 = qkjVedioPlayRecordLogs.get(i);
                                playTime = playTime + qkjVedioPlayRecordLog1.getLearnTime();
                            }
                        }
                        byLiveId.setLearnTime(playTime / 1000 / 60);
                        copy.setQkjLive(byLiveId);
                    }
                    return copy;
                }).collect(Collectors.toList());
                return Result.success(collect);
            }
        }
        return Result.failed(BizCodeEnum.LEARNING_RECORD);
    }

    @Override
    public Result saveReceiptInformation(String memCard, Long id, String name, String phone, String adress) {
        if (StringUtils.isBlank(memCard)) {
            return Result.success(BizCodeEnum.NO_LOGIN);
        }
        //扣积分操作
        //查询当前用户积分
        QkjMemberTaskInfo byMemCard = qkjMemberTaskInfoDao.findByMemCard(memCard);
        //查询商品所需积分
        Optional<QkjIntegralGoods> byId = qkjIntegralGoodsDao.findById(id);
        if (byId != null && byId.isPresent()) {
            if (byId.get().getGoodsNeedPoints() > byMemCard.getMemResidualPoints()) {
                return Result.failed(BizCodeEnum.INSUFF_ICIENT);
            }
            QkjIntegralGoods qkjIntegralGoods = byId.get();
            Integer goodsNeedPoints = qkjIntegralGoods.getGoodsNeedPoints();
            Integer have = byMemCard.getMemResidualPoints() - goodsNeedPoints;
            byMemCard.setMemResidualPoints(have);
            qkjMemberTaskInfoDao.save(byMemCard);
            //积分明细更新
            QkjMemberTaskDetail qkjMemberTaskDetail = new QkjMemberTaskDetail();
            qkjMemberTaskDetail.setChangeType(0);
            qkjMemberTaskDetail.setMemCard(memCard);
            qkjMemberTaskDetail.setPoints(goodsNeedPoints);
            qkjMemberTaskDetail.setCompleteTime(Calendar.getInstance());
            qkjMemberTaskDetail.setType(1);
            qkjMemberTaskDetailDao.save(qkjMemberTaskDetail);
            //扣完积分再进行 保存收货地址
            QkjIntegralDetail qkjIntegralDetail = new QkjIntegralDetail();
            qkjIntegralDetail.setGoodsId(id.intValue());
            qkjIntegralDetail.setChangeTime(Calendar.getInstance());
            qkjIntegralDetail.setMemCard(memCard);
            qkjIntegralDetail.setIsSend(0);
            qkjIntegralDetail.setReceiveMemname(name);
            qkjIntegralDetail.setReceiveMemaddr(adress);
            qkjIntegralDetail.setReceiveMemmobile(phone);
            qkjIntegralDetailDao.save(qkjIntegralDetail);
            return Result.success(BizCodeEnum.SUCCESS);
        }
        return Result.failed(BizCodeEnum.FAILED);
    }

    @Override
    public Result getQrImg(String memCard) {
        List<QkjCommunity> list = qkjCommunityDao.getQrImg();
        if (list != null && !list.isEmpty()) {
            return Result.success(list);
        }
        return Result.failed(BizCodeEnum.DATA_EMPTY);
    }

    @Override
    public Result findUserInfoWithSm(String memCard) {
        //解密身份证号
        QkjMemberPersonalAuth memberPersonalAuth = qkjMemberPersonalAuthDao.findByMemCard(memCard);

        QkjMemberPersonalAuthDto qkjMemberDto = new QkjMemberPersonalAuthDto();
        if (Objects.nonNull(memberPersonalAuth)) {
            qkjMemberDto = CopyUtil.copy(memberPersonalAuth, QkjMemberPersonalAuthDto.class);
            String decrypt = identificationNumberEncryptor.decrypt(qkjMemberDto.getMemIdentityId());
            qkjMemberDto.setMemIdentityId(StringUtil.reNo(decrypt));

            if (StringUtils.isNotBlank(qkjMemberDto.getMemExp()) && qkjMemberDto.getMemExp().contains("-")) {
                String memExp = Strings.EMPTY;
                switch (qkjMemberDto.getMemExp()) {
                    case "1-3":
                        memExp = "1";
                        break;
                    case "3-5":
                        memExp = "2";
                        break;
                    case "5-10":
                        memExp = "3";
                        break;
                    case "10-15":
                        memExp = "4";
                        break;
                    case "-1":
                        break;

                }
                qkjMemberDto.setMemExp(memExp);
            }
        }
        return Result.success(qkjMemberDto);
    }



    @Override
    public Result findUserInfoWithYs(String memCard) {
        return Result.success(qkjCertificatePhysiciansDao.findByMemCard(memCard));
    }

    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public Result saveUserDorec(String memCard, Integer oprType, Integer objType, Integer objId, Integer source, String url, String ip) {
        if(url.length()>255){
            String substring = url.substring(0, 255);
            url = substring;
        }
        QkjMemberDorec dorec = new QkjMemberDorec();
        dorec.setMemCard(memCard);
        dorec.setIp(ip);
        dorec.setOprType(oprType);
        dorec.setObjType(objType);
        dorec.setObjId(objId);
        dorec.setSource(source);
        dorec.setUrl(url);
        dorec.setOprTime(Calendar.getInstance());
        memberDorecDao.save(dorec);

        if (StringUtils.isNotBlank(memCard) && oprType == 1 && objType == 1) {
            //浏览文章
            //是否是今天第一次阅读
            List<QkjMemberDorec> dorecs = memberDorecDao.findTodayLogs(memCard, oprType, objType, objId);
            if (dorecs.size() == 1) {
                QkjMemberTask task = taskService.judeFinishTask(memCard, 27);
                if (task != null) {
                    taskService.dailyCheckIn(memCard, 27, 0);
                }
                return Result.success(task);
            }
        } else if (StringUtils.isNotBlank(memCard) && oprType == 2) {
            //分享
            //是否是今天第一次分享此链接
            List<QkjMemberDorec> dorecs = memberDorecDao.findTodayLogs(memCard, oprType, url);
            if (dorecs.size() == 1) {
                QkjMemberTask task = taskService.judeFinishTask(memCard, 21);
                if (task != null) {
                    taskService.dailyCheckIn(memCard, 21, 0);
                }
                return Result.success(task);
            }

        }
        return Result.success(BizCodeEnum.SUCCESS);
    }

    public List<DaliyCheckInDTO> sign(String memCard) throws ParseException {
        // 连续签到信息
        int curDay = 0;// 判断是否当天
        String time = "2019-09-17";
        // Calendar time=DateUtil.getCalendarByStr(timeStr);
        List<DaliyCheckInDTO> ins = new ArrayList<>();
        Calendar nowC = Calendar.getInstance();
        List<Object> checkIn = qkjMemberTaskDetailDao.sevenDayCheckIn(memCard, time);
        if (checkIn != null && checkIn.size() == 1) {
            Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(checkIn.get(0) + "");
            Timestamp t1 = new Timestamp(parse.getTime());
            Calendar time1 = Calendar.getInstance();
            time1.setTime(t1);
            if (time1.get(Calendar.DAY_OF_YEAR) == nowC.get(Calendar.DAY_OF_YEAR) || nowC.get(Calendar.DAY_OF_YEAR) - time1.get(Calendar.DAY_OF_YEAR) == 1) {
                DaliyCheckInDTO in = new DaliyCheckInDTO();
                if (time1.get(Calendar.DAY_OF_YEAR) == nowC.get(Calendar.DAY_OF_YEAR)) {
                    in.setIsCuur(1);
                    curDay = 1;
                } else {
                    in.setIsCuur(0);
                }
                in.setDayCalendar(time1);
                in.setDayNum(1);
                in.setDayPoints(10);
                in.setIsTodayChenckIn(1);
                ins.add(in);
            }
        } else if (checkIn != null && checkIn.size() != 1 && checkIn.size() != 0) {
            Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(checkIn.get(checkIn.size() - 1) + "");
            Timestamp t3 = new Timestamp(parse.getTime());
            Calendar time3 = Calendar.getInstance();
            time3.setTime(t3);
            // 判断 最后签到是否是前一天或者当天 若都不是这两种情况 就可以判断为 当天为第一天了
            if (time3.get(Calendar.DAY_OF_YEAR) == nowC.get(Calendar.DAY_OF_YEAR) || nowC.get(Calendar.DAY_OF_YEAR) - time3.get(Calendar.DAY_OF_YEAR) == 1) {
                for (int i = 1; i < checkIn.size(); i++) {
                    {
                        if (checkIn.get(i - 1) != null && checkIn.get(i) != null) {
                            Date p = new SimpleDateFormat("yyyy-MM-dd").parse(checkIn.get(i - 1) + "");
                            Timestamp t1 = new Timestamp(p.getTime());
                            Calendar time1 = Calendar.getInstance();
                            time1.setTime(t1);
                            Integer day1 = time1.get(Calendar.DAY_OF_YEAR);

                            Date tp2 = new SimpleDateFormat("yyyy-MM-dd").parse(checkIn.get(i) + "");
                            Timestamp t2 = new Timestamp(tp2.getTime());
                            Calendar time2 = Calendar.getInstance();
                            time2.setTime(t2);
                            Integer day2 = time2.get(Calendar.DAY_OF_YEAR);
                            if (day2 - day1 != 1) {
                                ins = new ArrayList<>();
                                DaliyCheckInDTO in = new DaliyCheckInDTO();
                                if (time2.get(Calendar.DAY_OF_YEAR) == nowC.get(Calendar.DAY_OF_YEAR)) {
                                    in.setIsCuur(1);
                                    curDay = 1;
                                } else {
                                    in.setIsCuur(0);
                                }
                                in.setDayCalendar(time2);
                                in.setDayNum(1);
                                in.setDayPoints(10);
                                in.setIsTodayChenckIn(1);
                                ins.add(in);
                            } else {
                                if (i == 1) {
                                    DaliyCheckInDTO in = new DaliyCheckInDTO();
                                    in.setDayCalendar(time1);
                                    in.setDayNum(i);
                                    in.setDayPoints(i * 10);
                                    in.setIsTodayChenckIn(1);
                                    if (time1.get(Calendar.DAY_OF_YEAR) == nowC.get(Calendar.DAY_OF_YEAR)) {
                                        in.setIsCuur(1);
                                        curDay = 1;
                                    } else {
                                        in.setIsCuur(0);
                                    }
                                    ins.add(in);

                                    in = new DaliyCheckInDTO();
                                    in.setDayCalendar(time2);
                                    in.setDayNum(i + 1);
                                    in.setDayPoints((i + 1) * 10);
                                    in.setIsTodayChenckIn(1);
                                    if (time2.get(Calendar.DAY_OF_YEAR) == nowC.get(Calendar.DAY_OF_YEAR)) {
                                        in.setIsCuur(1);
                                        curDay = 1;
                                    } else {
                                        in.setIsCuur(0);
                                    }
                                    ins.add(in);
                                } else {
                                    DaliyCheckInDTO in = new DaliyCheckInDTO();
                                    in.setDayCalendar(time2);
                                    in.setDayNum(ins.size() + 1);
                                    in.setDayPoints((ins.size() + 1) * 10);
                                    in.setIsTodayChenckIn(1);
                                    if (time2.get(Calendar.DAY_OF_YEAR) == nowC.get(Calendar.DAY_OF_YEAR)) {
                                        in.setIsCuur(1);
                                        curDay = 1;
                                    } else {
                                        in.setIsCuur(0);
                                    }
                                    ins.add(in);
                                }
                            }
                        }
                    }
                }
            }

        }
        List<Object> checkInEn = qkjMemberTaskDetailDao.sevenDayCheckInEn(memCard, time);
        if (ins.size() == 0) {
            DaliyCheckInDTO in = new DaliyCheckInDTO();
            in.setDayCalendar(Calendar.getInstance());
            in.setDayNum(1);
            in.setDayPoints(10);
            in.setIsTodayChenckIn(0);
            in.setIsCuur(1);
            curDay = 1;
            ins.add(in);
        } else if (ins.size() == 6 && checkInEn.size() == 7) {
            // 当天没有签到
            // 获取前七天的签到 得到 连续签到6天
            // 获取前八天的签到 得到 连续签到7天
            // 这种情况下 连续签到的6天里面
            // 若又积分为10的 若有从10积分那一天为第一天
            // 若没有 就从当天为第一天

            List<Object> checkInFir = qkjMemberTaskDetailDao.sevenDayCheckInFirst(memCard, time);
            if (checkInFir == null || checkInFir.size() == 0) {
                ins = new ArrayList<>();
                DaliyCheckInDTO in = new DaliyCheckInDTO();
                in.setDayCalendar(Calendar.getInstance());
                in.setDayNum(1);
                in.setDayPoints(10);
                in.setIsTodayChenckIn(0);
                in.setIsCuur(1);
                curDay = 1;
                ins.add(in);
            } else {
                // 判断连续签到记录里面 是否有 第一天标识（积分为10）
                int numNew = 0;
                Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(checkInFir.get(checkInFir.size() - 1) + "");
                Timestamp t1 = new Timestamp(parse.getTime());
                Calendar time1 = Calendar.getInstance();
                time1.setTime(t1);
                Integer day1 = time1.get(Calendar.DAY_OF_YEAR);
                List<DaliyCheckInDTO> insNew = new ArrayList<>();
                for (int i = 0; i < ins.size(); i++) {
                    Integer day = ins.get(i).getDayCalendar().get(Calendar.DAY_OF_YEAR);
                    if (day >= day1) {
                        numNew++;
                        ins.get(i).setDayPoints(numNew * 10);
                        ins.get(i).setDayNum(numNew);
                        insNew.add(ins.get(i));
                        if (ins.get(i).getIsCuur() == 1) {
                        }
                    }
                }
                if (insNew != null && insNew.size() != 0) {
                    ins = new ArrayList<>();
                    for (int i = 0; i < insNew.size(); i++) {
                        ins.add(insNew.get(i));
                    }
                }
            }
        } else if (ins.size() == 7 && checkInEn.size() == 8) {
            // 当天已经签到
            // 获取前七天的签到 得到 连续签到7天
            // 获取前八天的签到 得到 连续签到8天
            // 这种情况
            // 这种情况下 连续签到的7天里面
            // 若有积分为10的 若有从10积分那一天为第一天
            // 若没有 就从当天为第一天

            List<Object> checkInFir = qkjMemberTaskDetailDao.sevenDayCheckInFirst(memCard, time);
            if (checkInFir == null || checkInFir.size() == 0) {
                Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(checkInEn.get(checkInEn.size() - 1) + "");
                Timestamp tbefore = new Timestamp(parse.getTime());
                Calendar timebefore = Calendar.getInstance();
                timebefore.setTime(tbefore);

                ins = new ArrayList<>();
                DaliyCheckInDTO in = new DaliyCheckInDTO();
                in.setDayCalendar(timebefore);
                in.setDayNum(1);
                in.setDayPoints(10);
                in.setIsTodayChenckIn(1);
                in.setIsCuur(1);
                curDay = 1;
                ins.add(in);
            } else {
                // 判断连续签到记录里面 是否有 第一天标识（积分为10）
                int numNew = 0;
                Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(checkInFir.get(checkInFir.size() - 1) + "");
                Timestamp t1 = new Timestamp(parse.getTime());
                Calendar time1 = Calendar.getInstance();
                time1.setTime(t1);
                Integer day1 = time1.get(Calendar.DAY_OF_YEAR);
                List<DaliyCheckInDTO> insNew = new ArrayList<>();
                for (int i = 0; i < ins.size(); i++) {
                    Integer day = ins.get(i).getDayCalendar().get(Calendar.DAY_OF_YEAR);
                    if (day >= day1) {
                        numNew++;
                        ins.get(i).setDayPoints(numNew * 10);
                        ins.get(i).setDayNum(numNew);
                        insNew.add(ins.get(i));
                        if (ins.get(i).getIsCuur() == 1) {
                        }
                    }
                }
                if (insNew != null && insNew.size() != 0) {
                    ins = new ArrayList<>();
                    for (int i = 0; i < insNew.size(); i++) {
                        ins.add(insNew.get(i));
                    }
                }
            }
        }
        Integer size = ins.size();
        if (size < 7) {
            for (int j = 0; j < 7 - size; j++) {
                DaliyCheckInDTO in = new DaliyCheckInDTO();
                DaliyCheckInDTO last = ins.get(ins.size() - 1);
                if (j == 0 && curDay == 0) {
                    in.setIsCuur(1);
                } else {
                    in.setIsCuur(0);
                }
                Calendar nextTime = last.getDayCalendar();
                nextTime.add(Calendar.DAY_OF_YEAR, 1);
                in.setDayCalendar(nextTime);
                in.setDayNum(last.getDayNum() + 1);
                in.setDayPoints((last.getDayNum() + 1) * 10);
                in.setIsTodayChenckIn(0);
                ins.add(in);
            }
        }
        return ins;
    }

    public void updateAllIDNumber() {
        Iterable<QkjMemberPersonalAuth> list = qkjMemberPersonalAuthDao.findAll();
        for (QkjMemberPersonalAuth entity : list) {
            String idNumber = entity.getMemIdentityId();
            if (StringUtils.isBlank(idNumber)) continue;
            idNumber = idNumber.trim();
            if (idNumber.length() != 15 && idNumber.length() != 18) continue;
            if (!StringUtils.isNumeric(idNumber.substring(0, 14))) continue;
            String encrypted = identificationNumberEncryptor.encrypt(idNumber);
            entity.setMemIdentityId(encrypted);
        }
    }

}
