liujie
昨天 918e3f07f06b36746959add0109c60bd4c376a5c
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package com.panzhihua.sangeshenbian.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.redis.RedisUtils;
import com.panzhihua.sangeshenbian.model.dto.UserIdentityDTO;
import com.panzhihua.sangeshenbian.model.entity.Banner;
import com.panzhihua.sangeshenbian.model.entity.PartyMember;
import com.panzhihua.sangeshenbian.model.entity.SystemUser;
import com.panzhihua.sangeshenbian.model.entity.SystemUserLevel;
import com.panzhihua.sangeshenbian.model.query.BasePage;
import com.panzhihua.sangeshenbian.model.vo.ComplaintTodoVO;
import com.panzhihua.sangeshenbian.model.vo.MessageNotificationVO;
import com.panzhihua.sangeshenbian.model.vo.PartyCardInfoVO;
import com.panzhihua.sangeshenbian.service.*;
import com.panzhihua.sangeshenbian.utils.BaiduMapUtil;
import com.panzhihua.sangeshenbian.warpper.IdentityInformation;
import com.panzhihua.sangeshenbian.warpper.IdentityInformationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
/**
 * @author mitao
 * @date 2025/2/23
 */
@RestController
@RequestMapping("/applet/home")
@RequiredArgsConstructor(onConstructor_ = @Lazy)
@Api(tags = "首页相关接口")
public class HomeController extends BaseController {
    private final IBannerService bannerService;
    private final IMessageNotificationService messageNotificationService;
    private final IComplaintService complaintService;
    private final ISystemUserService systemUserService;
    private final IPartyMemberService partyMemberService;
    private final RedisUtils redisUtils;
    private final IdentityInformationService identityInformationService;
    private final ISystemUserLevelService systemUserLevelService;
    @ApiOperation("获取banner列表")
    @GetMapping("/banner-list")
    public R<List<Banner>> getBannerList() {
        return R.ok(bannerService.list());
    }
 
    @GetMapping("/party-card-info")
    @ApiOperation("获取党员证信息")
    public R<PartyCardInfoVO> getPartyCardInfo() {
        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
        // 获取党员信息
        PartyMember partyMember = partyMemberService.getOne(new LambdaQueryWrapper<PartyMember>()
                .eq(PartyMember::getPhone, loginUserInfo.getPhone())
                .eq(PartyMember::getAuditStatus, 1)
                .eq(PartyMember::getDelFlag, 0));
 
        PartyCardInfoVO partyCardInfoVO = new PartyCardInfoVO();
        partyCardInfoVO.setAvatar(partyMember.getAvatar());
        partyCardInfoVO.setName(partyMember.getName());
        partyCardInfoVO.setIdCard(partyMember.getIdNumber());
        partyCardInfoVO.setDistricts(partyMember.getDistricts());
        partyCardInfoVO.setStreet(partyMember.getStreet());
        partyCardInfoVO.setCommunity(partyMember.getCommunity());
        partyCardInfoVO.setPartyOrganization(partyMember.getPartyOrganization());
        return R.ok(partyCardInfoVO);
    }
 
    @PostMapping("/message")
    @ApiOperation("获取消息列表")
    public R<Page<MessageNotificationVO>> getMessageList(@RequestBody BasePage page) {
        return R.ok(messageNotificationService.getMessageList(page, getUserId()));
    }
 
    @PostMapping("/todo-list")
    @ApiOperation("获取待办诉求")
    public R<Page<ComplaintTodoVO>> getTodoList(@RequestBody BasePage page) {
        return R.ok(complaintService.getTodoList(page, getLoginUserInfo()));
    }
 
    @GetMapping("/current-user-info")
    @ApiOperation("获取三个身边当前用户信息 用于判断用户是否是上级")
    public R<SystemUser> getCurrentUserInfo() {
        SystemUser systemUser = systemUserService.getSystemUserAdminByPhone(getLoginUserInfo().getPhone()).orElse(null);
        Object o1 = redisUtils.get("identity:" + getLoginUserInfo().getPhone());
        if(o1!=null){
            UserIdentityDTO o2 = (UserIdentityDTO) o1;
            Integer levelId = o2.getLevelId();
            if(levelId!=null) {
                SystemUserLevel systemUserLevel = systemUserLevelService.getById(levelId);
                if (systemUserLevel == null) {
                    List<SystemUserLevel> list = systemUserLevelService.list(new LambdaQueryWrapper<SystemUserLevel>().eq(SystemUserLevel::getSystemUserId, systemUser.getId()).eq(SystemUserLevel::getStatus, 1));
                    if (list.size() > 0) {
                        systemUser.setLevelId(list.get(0).getLevel());
                    }
                } else {
                    systemUser.setLevelId(systemUserLevel.getLevel());
                }
            }else {
                List<SystemUserLevel> list = systemUserLevelService.list(new LambdaQueryWrapper<SystemUserLevel>().eq(SystemUserLevel::getSystemUserId, systemUser.getId()).eq(SystemUserLevel::getStatus, 1));
                if (list.size() > 0) {
                    systemUser.setLevelId(list.get(0).getLevel());
                }
            }
        }
        return R.ok(systemUser);
    }
 
    /**
     * 标记已读
     */
    @PostMapping("/read")
    @ApiOperation("标记已读")
    public R<?> read() {
        messageNotificationService.read(getLoginUserInfo());
        return R.ok();
    }
 
    /**
     * 百度地图圆形区域检索
     *
     * @param query
     * @param location
     * @return
     */
    @GetMapping("/search-location")
    @ApiOperation("百度地图圆形区域检索")
    public R<JSONArray> searchLocation(String query, String location) {
        return R.ok(BaiduMapUtil.searchLocation(query, location));
    }
    @GetMapping("/geoconv")
    @ApiOperation("百度地图经纬度转换")
    public R<JSONObject> geoconv(String coords) {
        try {
            return R.ok(BaiduMapUtil.geoconv(coords));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * 获取身份信息
     */
    @GetMapping("/identity-info")
    @ApiOperation("获取身份信息")
    public R<IdentityInformationVO> getIdentityInfo() {
        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
        IdentityInformation identityInformation = identityInformationService.getIdentityInformation(loginUserInfo);
        IdentityInformationVO identityInformationVO = new IdentityInformationVO();
        BeanUtils.copyProperties(identityInformation, identityInformationVO);
        return R.ok(identityInformationVO);
    }
 
 
 
    /**
     * 切换身份
     */
    @GetMapping("/change-identity")
    @ApiOperation("切换身份")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "identity", value = "身份 1:党员 2:管理员", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "levelId", value = "身份层级id,党员身份不传,管理员必传", required = true, dataType = "Integer")
    })
    public R<?> changeIdentity(@RequestParam(value = "identity", required = true) Integer identity,
                               @RequestParam(value = "levelId", required = false) Integer levelId) {
        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
        if (identity.equals(2) && Objects.isNull(levelId)) {
            throw new ServiceException("管理员所属层级id不能为空");
        }
        // 存储到Redis
        redisUtils.set("identity:" + loginUserInfo.getPhone(), UserIdentityDTO.builder()
                .identity(identity)
                .levelId(levelId)
                .build());
        return R.ok();
    }
 
    /**
     * 提示内容确认
     */
    @GetMapping("/confirm-content")
    @ApiOperation("提示内容确认")
    public R<?> confirmContent() {
        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
        redisUtils.set("confirmContent:" + loginUserInfo.getPhone(), 1);
        return R.ok();
    }
}