Ideas and logic of dating projects

Foreground interface:

Registration interface: First, we can use the mobile phone number provided by Alipay to send a verification code function, and then we use this function to send a verification code to the user's mobile phone number, and then we save the verification code in the form of a one-minute expiration time Redis is used as a necessity for subsequent login, and the mobile phone number sent by the user is stored in our database user table as a proof of successful registration. Afterwards, we can use this mobile phone number to complete the user's login and fill in relevant information .

Login interface:

In the above registration process, we got a login credential by sending the verification code, and then we used this verification code to verify the login within one minute. If the verification code is wrong, it means that the user is not registered. If the verification code is correct, let the user fill in their own Relevant information such as gender, age, name and other related information, and then compare the incoming mobile phone number with the mobile phone number registered in the database before updating the user's information, and then we use uuid or other methods to generate a Token code and save the Token Entering redis as the only credential of the login, all subsequent interface access must have the support of this Token to operate, this is the login process

 Check out the interface of today's interesting soul:

First of all, this interface has three parts, which are the display of users who have visited me today, the display of the most popular users, and the display of list users. First of all, we are working on the interface of recent visits. The visits are all recent visits, and then I started to build tables, namely the user table and the access record table. In the access record table, we need to use three fields, which are the user id, the viewer's id, and the viewing time. After that, we need a sql to Associate the user table with this access record table and judge that the access time cannot be longer than seven days. After that, store the result of this SQL query into a List collection and return it to the front end after traversal. After that, it can be our query today's best sum list There are some conditions for the users displayed in the above, which are the best, including that the displayed people must have something in common with you, such as the age difference is not more than two years old, or the relationship status is single, and the popularity of the users must be Gao, wait for these, with these conditions, I think it may be very difficult to just query in the database, so I put all these user information into ES, which is the search engine, and then I use es The relevant attribute method is used for conditional query. For example, use the keyword Filter to filter the age. The age is set to be the maximum age of 2 years and the minimum age of 2 years. If the relationship status is used, Should is used to specify the user who is consistent with the query. Information, and then the popularity value. Here, because es will automatically give the score and arrange it from high to low, so I directly gave some non-repeating random numbers in the middle of 99-85 as the popularity value, and then returned to the front end. One will be the best today, and the rest will be sorted and returned to the front end as order by popularity values ​​displayed in the list from high to low.

Emotional test interface:

The next step is our emotional test interface, because when doing the soul encounter operation, you need to answer some test questions first, and then get the person's personality according to the results of the test questions, and then match the person you meet according to the personality, there will be some Emotional test questions Here I need to write some interfaces to return these test questions to the front end. I need to write three tables, which are question table, option table, and user answer record table. The specific content of the table is such that the question table only has id and Question content, the option table has our option id and our corresponding question id, and the fields corresponding to the three options of ABCD, and the main function of the user answer record table is to store the user's previous answers like a log The question and answer have a user id and a json string of detailed information about the answer, as well as the score corresponding to abcd to judge the corresponding personality, and finally there is a field for creation time, and then we have these tables After that, we can write the logic in it. The specific logic is like this. First, we need to write an interface, which is like users randomly sending some test questions from our question bank for users to choose. This interface is specifically like this. I first wrote a The method is to randomly give twelve non-repeating numbers and then I call this method to generate twelve non-repeating numbers and then put them into my sql and use a list set to receive the return value. The specific sql is like this. I use the question table Go to left join to connect the option table and then in contains the twelve unique numbers I generated, which is my id in sql, and then return these data to get twelve questions and answer options

 

 This is the test question interface that I return to the front-end user. Next, we will receive the excuse after the user finishes the question. This is how it is implemented. First, we can create a DTO in the idea to receive these parameters. This dto There are these parameters, which are the id of the topic and the content of the topic, and then there is a collection of the id of the options and the four options of abcd and finally an id selected by the user. With these contents, we can do it This dto is returned as a return object, and then we receive the content according to the data filled in at the front desk, then judge the user's choice for each question, and then return to the database user answer table to store these data. Before storing, we need to store the data in the logic The layer makes some judgments, according to the user's choice of each topic, and then adds value to the corresponding abcd. First, the user answers the four options of abcd in the record form to a default value of 10, and then adds or equals the value according to the user's questions, such as If you choose two a and three b, then a will add 2 points and b will add three points. If the scores of abcd are the same, then e will be added as a full score, and then the result and the JSON string will be stored in the database to get The historical record of the user's questions. After finishing these, we need an interface. Now that the user's answer record has been stored in the database, what should the user do if he wants to see his own record? At this time, we also need a user to query his own answer The record interface, this is relatively simple, you only need to pass in a user id, and then use this id to query the record of the user's previous questions in the database, but this record was converted into a string and stored in it when we saved the data. , we need to perform a conversion to increase the user experience, and then return the queried collection object to the front end to attach the code.

 @Override
    public Result queryLoveResult(LoveResultAnswer loveResultAnswer) {
        loveResultAnswer.setCreatetime(new Date().getTime()/1000);
        List<AllLoveQuestionAndAnswerDTO> allLoveQuestionAndAnswerList = loveResultAnswer.getAllLoveQuestionAndAnswerList();
        //循环集合,取出每个结果,判断是哪个就给那个选项+1
        allLoveQuestionAndAnswerList.forEach(a ->{
            switch (a.getAnswer()){
                case "a":
                    loveResultAnswer.setDeviationA(loveResultAnswer.getDeviationA()+1);
                    break;
                case "b":
                    loveResultAnswer.setDeviationB(loveResultAnswer.getDeviationB()+1);
                    break;
                case "c":
                    loveResultAnswer.setDeviationC(loveResultAnswer.getDeviationC()+1);
                    break;
                case "d":
                    loveResultAnswer.setDeviationD(loveResultAnswer.getDeviationD()+1);
                    break;
            }
        });
        //如果四项结果相同则为结果e
        if (loveResultAnswer.getDeviationA()==loveResultAnswer.getDeviationB() &&
                loveResultAnswer.getDeviationA()==loveResultAnswer.getDeviationC() &&
                loveResultAnswer.getDeviationA()==loveResultAnswer.getDeviationD()){
            loveResultAnswer.setDeviationE(22);
        }
        TanswerPojo build = new TanswerPojo.Builder().createtime(loveResultAnswer.getCreatetime()).questionOpstionPojo(JSONArray.toJSONString(allLoveQuestionAndAnswerList)).deviationA(loveResultAnswer.getDeviationA()).deviationB(loveResultAnswer.getDeviationB()).deviationC(loveResultAnswer.getDeviationC()).deviationD(loveResultAnswer.getDeviationD()).deviationE(loveResultAnswer.getDeviationE())
                .userId(loveResultAnswer.getUserId()).build();

        userTanhuaMapper.addLoveResult(build);
        return Result.SUCCESS(build);
    }
 @Override
    public Result queryLoveTestingRecord(Integer userId) {
        TanswerPojo tanswerPojo= userTanhuaMapper.queryLoveTestingRecord(userId);
        if (tanswerPojo==null){
            return Result.ERROR();
        }
        String questionOpstionPojo = tanswerPojo.getQuestionOpstionPojo();
        List<AllLoveQuestionAndAnswerDTO> allLoveQuestionAndAnswerDTOS = JSONArray.parseArray(questionOpstionPojo, AllLoveQuestionAndAnswerDTO.class);
        LoveResultAnswer build = new LoveResultAnswer.Builder().allLoveQuestionAndAnswerList(allLoveQuestionAndAnswerDTOS).createtime(tanswerPojo.getCreatetime()).deviationA(tanswerPojo.getDeviationA())
                .deviationB(tanswerPojo.getDeviationB()).deviationC(tanswerPojo.getDeviationC()).deviationD(tanswerPojo.getDeviationE())
                .userId(tanswerPojo.getUserId()).build();
        return Result.SUCCESS(build);
    }

Soul encounter interface:

Next, after the user completes the questions, we can use the soul encounter function. Before doing this interface, we have to consider a problem that is the membership issue. If the user is a member, then the user can always have encounters. If not a member, limit this. A user can only meet 20 users in a month, and users who have already met by chance cannot meet again. Therefore, I choose to build a membership table and a user table corresponding to a member, and then I can judge whether the user is a member or not. The specific logic is this. We need an interface. This interface only needs to pass in the user id, and there is a method in it to query the user's score based on the id. After getting the user's score, we need to judge this based on the passed id. Whether the user is a member, and then write a method to check whether it is the data that the user has already queried. If so, it will not be displayed. Next, we will put the abcd scores of these users in a map and query this information, and then will The result of the query is stored in reids, and it will not appear when querying later. People who have met by chance can only check it in the history.

    @Override
    public Result soulMeet(Integer userId) {
         //* 1.根据用户id查到答题结果
        LoveResultAnswer loveResultAnswer = getLoveResultAnswer(userId);
        //先拿到ABCD的分值
        Integer deviationA = loveResultAnswer.getDeviationA();
        Integer deviationB = loveResultAnswer.getDeviationB();
        Integer deviationC = loveResultAnswer.getDeviationC();
        Integer deviationD = loveResultAnswer.getDeviationD();
        Integer deviationE = loveResultAnswer.getDeviationE();
        //* 2.查询会员状态
        Integer flag= userTanhuaMapper.queryUserSoulMemberInfo(userId);
        //* 3,查询所有该用户未查询过的数据
        Set members = redisTemplate.opsForSet().members("soul_user_" + userId);

        if (members.size()!=0 || members!=null){
            return Result.ERROR(999,"Redis中以有数据");
        }

        Map<String, Object> map = new HashMap<>();
        map.put("deviationA",deviationA);
        map.put("deviationB",deviationB);
        map.put("deviationC",deviationC);
        map.put("deviationD",deviationD);
        map.put("deviationE",deviationE);
        map.put("flag",flag);
        map.put("members",members);
        //* 4.如果不是会员,择取redis查询是否本月已查询过
        List<UserPojo>list= userTanhuaMapper.querySoulMeetMember(map);
        List<Integer> list1 = new ArrayList<>();
        list.forEach(a ->{
            list1.add(a.getUserId());
        });
        //将查过得用户id添加到redis中去
        redisTemplate.opsForSet().add("soul_user_"+userId,list);

         //* 5.已经偶遇过得人,只能去历史记录查找

        return Result.SUCCESS(list);
    }

Temporarily updated here, more interfaces will be updated later, love life, love code.

 love you guys。

Hello, I’m here to update. It’s the first working day after the National Day. Haha, are you having fun? I’ve completed a few interfaces. Here I’ll explain the logic to you in detail.

Query nearby interface:

After we finish the function of encountering souls, we also need to create an interface for querying nearby people. Because it is a dating software, querying nearby people is a relatively important function. Nearby people, as the name suggests, require our own location and users. location, so we need a tool class before implementing this function, which is such a toolkit that calculates our own distance according to latitude and longitude. Here I use a plug-in provided by Google Maps. I copy the tool class below

 /**

     * 默认地球半径

     */

    private static double EARTH_RADIUS = 6371000;//赤道半径(单位m)

    /**

     * 转化为弧度(rad)

     * */

    private static double rad(double d)

    {

        return d * Math.PI / 180.0;

    }

    /**

     * @param lon1 第一点的精度

     * @param lat1 第一点的纬度

     * @param lon2 第二点的精度

     * @param lat2 第二点的纬度

     * @return 返回的距离,单位m

     * */

    public static double GetDistance(double lon1,double lat1,double lon2, double lat2) {

        double radLat1 = rad(lat1);

        double radLat2 = rad(lat2);

        double a = radLat1 - radLat2;

        double b = rad(lon1) - rad(lon2);

        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));

        s = s * EARTH_RADIUS;

        s = Math.round(s * 10000) / 10000;

        return s;

    }

    public static void main(String[] args) {
        double v = GetDistance(113.63141921, 34.75343885, 113.63241921, 34.75343885);
        System.out.println("当前位置距离目标位置的距离是:"+v+"米");
    }

With this tool class, we can calculate the distance from one longitude and latitude to another longitude and latitude, so what should we do next? Of course, update our own longitude and latitude location information. I store this location information in the form of Hash in In redis, before using our interface, we will first update our latitude and longitude position, and then our redis will have our latitude and longitude information

 Next, we will write another interface to query nearby people, because we already have our latitude and longitude information in Redis, so we only need to take them out and traverse them. This is how it is implemented. We first We need to take out our own latitude and longitude for comparison, then traverse all the HashMap collections we store in redis to get the latitude and longitude of all users, and then create a new List collection for us to store these data, but before storing, we need to do a Judgment is to exclude yourself from this collection, because it is impossible and unnecessary to obtain your own information from the nearby people. After making this judgment, we can store the key-value pairs of all the nearby people in the new In this list collection, then we can call our tool class for distance measurement. First, we need to perform a for loop to cycle through these data and call the tool class for distance measurement. After we get these distances, we can sort them. If we sort them, we You can use the filter attribute in the stream to filter the distance, and then use the sorted attribute to perform natural sorting. After sorting, we can get the user ids of the nearby people data we have queried and then loop them to the database Just go to query the detailed information of this user.

    //传入自己距离,根据经纬度得到附近人信息
    @PostMapping("queryNearMember")
    public Result queryNearMember(Integer userId){
        //取得Redis中用户存进去的Hash键
        Map address = redisTemplate.opsForHash().entries("address");
        //根据Hash键获取到自己的用户id
        String str =(String)address.get("user_" + userId);
        NearMember aaa = aaa(str);//自己的经纬度
        //遍历
        List<NearMember> list = new ArrayList<>();
        //获取到这个键中的所有键值对
        Set set = address.keySet();
        //遍历这些键值对
        set.forEach(a->{
            //分割key 只需要后面的userID
            Integer NearuserId = Integer.parseInt(a.toString().substring(5)) ;
            //如果得到的UserId中不包含传入的userid就进入
            if (!NearuserId.equals(userId)){
                String s = address.get(a).toString();
                NearMember aaa1 = aaa(s);
                aaa1.setUserId(NearuserId);
                list.add(aaa1);
            }
        });
        //list里有所有附近的人的经纬度
        //循环得到所有人离我的距离
        list.forEach(a->{
            double v = NearDistanceUtil.GetDistance(aaa.getLon(), aaa.getLat(), a.getLon(), a.getLat());
            a.setDistance(v);
        });
        //排序 根据Stream流中提供的过滤方法 查询到距离在五公里以内的用户正序排序
        List<NearMember> collect = list.stream().filter(a -> a.getDistance() <= 5000).sorted(Comparator.comparing(NearMember::getDistance)).collect(Collectors.toList());
        List<UserPojo>list1=new ArrayList<>();
        //将查询到的附近人数据的用户id获取到然后进行循环 到数据库中查询获得用户详细的信息
        for (int i = 0; i < collect.size(); i++) {
            NearMember nearMember = collect.get(i);
            Integer userId1 = nearMember.getUserId();
            Double distance = nearMember.getDistance();
            UserPojo userPojo=userTanhuaService.queryUser(userId1);
            userPojo.setDistance(distance);
            list1.add(userPojo);
        }
        return Result.SUCCESS(list1);
    }

Taohua audio interface:

Next, after the nearby people are finished, there is still a small function that needs to be done, which is the peach blossom sound transmission, which is similar to the drifting bottle function in WeChat. It can send and receive voices. Each person can only send ten messages a day, and can only receive ten messages. , Next, I will give you a detailed description of my implementation process...First of all, start with sending voice. We need to build a voice table in the database. There are several fields in this table that are primary keys id, user id, creation time and the recording path uploaded by the user. Here, the way I upload the recording is to store the audio in the space of Alibaba Cloud oss ​​object storage. The path path that can be obtained in this space is this audio , so we only need to store this path in the database, because there is a limit that each user can only upload 10 voices per day, so we need to go to this table to check how many voices this user has sent that day before uploading recordings So we need a query method

 After that, we can upload the recording. We need two parameters: the user id and the file, and then we call the tool class of Alibaba Cloud oss ​​to pass the file passed by the user into oss, and then call the query method just now. If this If the user has sent ten or more messages today, this information will be returned to the user. Otherwise, we can store the user id, voice path and current time in the database. This is how we send voices from Taohua Transsion

 Next, we can carry out the interface of randomly receiving voices. For this interface, I still need to create a database table called the listener table. There are several fields in it: primary key id, user id, listening times, current date, these few The field I wrote is more troublesome and complicated, because I don’t use redis cache middleware, you can consider using redis, the specific logic is this, first we need to make a judgment, that is, whether the date is the current date, if the incoming user If the date is not the current date, then update the date and change the number of listening times to 0. If the current date is the current date, then make the following judgment to determine whether the current incoming user id exists. If not, create a new user and assign it to the current The date, user id, and number of views are 0. If the user id exists, then update the user id so that its listening times will be increased by 1. After that, we can query the current user's query times and only need to pass Enter the user id and then query the number of listening times. If it is greater than 10, this information will be returned to the user. After that, we can query the voice sent by the user. We only need to use a random number to achieve it. Random is a random number and then give this query method, but before writing this query method, you need to make a judgment, that is, the currently found user id cannot be consistent with the id passed in by yourself. If it is consistent, it means that you have received your own voice again, and then the queried data Just return it.

 @Override
    public Result queryMemberMp3(Integer userId) {
        Date date = new Date();
        LookMp3 lookMp3= userTanhuaMapper.queryLookMp3(userId);
        LookMp3 lookMp31 = new LookMp3();
        if (lookMp3!=null && lookMp3.getCreateTime().getDay()!=date.getDay()){
            lookMp31.setUserId(userId);
            lookMp31.setLookCount(0);
            userTanhuaMapper.updateLookMp3Bydate(lookMp31);
        }else {

        if (lookMp3!=null && lookMp3.getUserId()!=null){
            lookMp3.setUserId(userId);
            lookMp3.setLookCount(lookMp3.getLookCount()+1);
            userTanhuaMapper.updateLookMp3(lookMp3);
        }else {
            lookMp31.setUserId(userId);
            lookMp31.setLookCount(lookMp31.getLookCount());
            userTanhuaMapper.addLookMp3(lookMp31);
        }
          }
       //查询当前用户查询次数
        LookMp3 lookMp30= userTanhuaMapper.queryLookMp3Count(userId);
        Integer lookCount = lookMp30.getLookCount();
        if (lookCount>=10){
            return Result.ERROR(998,"今日查看已达上限");
        }
        List<MemberMp3>list=userTanhuaMapper.queryMp3();
        int random=(int)(Math.random()*10+1);
        List<MemberMp3>memberMp3s= userTanhuaMapper.queryMemberMp3(random);
        for (int i = 0; i < memberMp3s.size(); i++) {
            MemberMp3 memberMp3 = memberMp3s.get(i);
            Integer userId1 = memberMp3.getUserId();
            if (!userId1.equals(userId)){
                return Result.SUCCESS(memberMp3s);
            }
        }
        return Result.SUCCESS("未查询到,稍后再试");
    }

I will continue to update after updating here first, love life, love code.

Guess you like

Origin blog.csdn.net/m0_67864787/article/details/127086482