admin
2022-04-29 6cc97918a5a42e37a3c3867cc5b78a0b9fd43a24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.yeshi.makemoney.app.controller.client.api;
 
import com.google.gson.*;
import com.yeshi.makemoney.app.entity.msg.AppPageNotifyMsg;
import com.yeshi.makemoney.app.entity.msg.UserMsg;
import com.yeshi.makemoney.app.entity.team.TeamInviteRelation;
import com.yeshi.makemoney.app.entity.team.UserSpreadImg;
import com.yeshi.makemoney.app.entity.user.UserInfo;
import com.yeshi.makemoney.app.exception.team.SpreadImgException;
import com.yeshi.makemoney.app.exception.team.TeamInviteRelationException;
import com.yeshi.makemoney.app.exception.team.UserSpreadImgException;
import com.yeshi.makemoney.app.exception.user.UserInfoException;
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetRecordService;
import com.yeshi.makemoney.app.service.inter.msg.AppPageNotifyMsgService;
import com.yeshi.makemoney.app.service.inter.msg.UserMsgService;
import com.yeshi.makemoney.app.service.inter.team.TeamInviteRelationService;
import com.yeshi.makemoney.app.service.inter.team.UserSpreadImgService;
import com.yeshi.makemoney.app.service.inter.user.UserExtraInfoService;
import com.yeshi.makemoney.app.service.inter.user.UserInfoService;
import com.yeshi.makemoney.app.service.query.msg.UserMsgQuery;
import com.yeshi.makemoney.app.utils.Constant;
import com.yeshi.makemoney.app.utils.annotation.UserLogin;
import com.yeshi.makemoney.app.vo.AcceptData;
import com.yeshi.makemoney.app.vo.msg.AppPageNotifyMsgVO;
import com.yeshi.makemoney.app.vo.msg.UserMsgVO;
import com.yeshi.makemoney.app.vo.team.TeamInfoVO;
import com.yeshi.makemoney.app.vo.team.TeamMemberListVO;
import com.yeshi.makemoney.app.vo.user.UserInfoVO;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yeshi.utils.BigDecimalUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.ThreadUtil;
import org.yeshi.utils.TimeUtil;
 
import javax.annotation.Resource;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author hxh
 * @title: TeamController
 * @description: 团队接口
 * @date 2021/11/16 17:37
 */
@Controller
@RequestMapping("api/v1/msg")
public class MsgController {
 
    @Resource
    private AppPageNotifyMsgService appPageNotifyMsgService;
 
    @Resource
    private UserMsgService userMsgService;
 
 
    /**
     * @return java.lang.String
     * @author hxh
     * @description 获取应用内通知信息
     * @date 10:50 2022/4/24
     * @param: acceptData
     * @param: type
     **/
    @ResponseBody
    @RequestMapping("getNotifyMsg")
    public String getNotifyMsg(AcceptData acceptData, String type) {
        AppPageNotifyMsg.AppPageNotifyMsgType msgType = AppPageNotifyMsg.AppPageNotifyMsgType.valueOf(type);
        if (msgType == null) {
            return JsonUtil.loadFalseResult("类型错误");
        }
        AppPageNotifyMsg msg = appPageNotifyMsgService.selectByType(acceptData.getSystem(), msgType, new Date());
        if (msg == null) {
            return JsonUtil.loadFalseResult("暂无通知消息");
        }
        return JsonUtil.loadTrueResult(AppPageNotifyMsgVO.create(msg));
    }
 
 
    @UserLogin(uid = "#uid")
    @ResponseBody
    @RequestMapping("getUserMsg")
    public String getUserMsg(AcceptData acceptData, Long uid, int page) {
        UserMsgQuery query = new UserMsgQuery();
        query.setUid(uid);
 
        List<UserMsg> msgList = userMsgService.list(query, page, Constant.PAGE_SIZE);
        long count = userMsgService.count(query);
 
 
        Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
            @Override
            public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
                return value == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy.MM.dd HH:mm"));
            }
        }).create();
 
        List<UserMsgVO> voList = new ArrayList<>();
        if (msgList != null) {
            voList = msgList.stream().map(item -> {
                return UserMsgVO.create(item);
            }).collect(Collectors.toList());
 
        }
 
        JSONObject data = new JSONObject();
        data.put("list", gson.toJson(voList));
        data.put("count", count);
        ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                userMsgService.readAllMsg(uid);
            }
        });
        return JsonUtil.loadTrueResult(data);
    }
 
 
}