xuhy
2 小时以前 26f6f43785afd992496d7fc79775124e557ff16d
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
package com.ruoyi.web.controller.api;
 
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.UpdateDetailTeamDto;
import com.ruoyi.system.dto.UserIdDto;
import com.ruoyi.system.model.TAppUser;
import com.ruoyi.system.model.TAppUserEquipment;
import com.ruoyi.system.model.TAppUserLocation;
import com.ruoyi.system.service.TAppUserEquipmentService;
import com.ruoyi.system.service.TAppUserLocationService;
import com.ruoyi.system.service.TAppUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import java.time.LocalDate;
 
import java.util.List;
 
/**
 * <p>
 * 人员管理 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-09-28
 */
@Api(tags = "人员管理")
@RestController
@RequestMapping("")
public class TAppUserController {
 
    private final TAppUserService appUserService;
    private final TokenService tokenService;
    private final PasswordEncoder passwordEncoder;
    private final TAppUserEquipmentService appUserEquipmentService;
    private final TAppUserLocationService appUserLocationService;
    private final RedisCache redisCache;
    @Autowired
    public TAppUserController(TAppUserService appUserService, TokenService tokenService, PasswordEncoder passwordEncoder, TAppUserEquipmentService appUserEquipmentService, TAppUserLocationService appUserLocationService, RedisCache redisCache) {
        this.appUserService = appUserService;
        this.tokenService = tokenService;
        this.passwordEncoder = passwordEncoder;
        this.appUserEquipmentService = appUserEquipmentService;
        this.appUserLocationService = appUserLocationService;
        this.redisCache = redisCache;
    }
 
    /**
     * 添加人员管理管理管理
     */
    @ApiOperation(value = "注册人员管理",notes = "请求参数:TAppUser对象",response = TAppUser.class)
    @PostMapping(value = "/api/t-app-user/add")
    public R<Boolean> add(@RequestBody String param) {
        TAppUser dto = JSON.parseObject(param,TAppUser.class);
        long count = appUserService.count(Wrappers.lambdaQuery(TAppUser.class).eq(TAppUser::getAccount, dto.getAccount()));
        if (count>0) {
            return R.fail("该账号已存在");
        }
        dto.setState(0);
        dto.setStatus(1);
        dto.setPassword(passwordEncoder.encode(dto.getPassword()));
        appUserService.save(dto);
        return R.ok();
    }
 
    /**
     * 查看人员管理详情
     */
    @ApiOperation(value = "查看人员管理详情")
    @GetMapping(value = "/open/t-app-user/getDetailById")
    public R<TAppUser> getDetailById() {
        String userId = tokenService.getLoginUserApplet().getUserId();
        TAppUser appUser = appUserService.getById(userId);
        return R.ok(appUser);
    }
 
 
 
    /**
     * 查看人员管理详情--队伍情况
     */
    @ApiOperation(value = "查看人员管理详情--队伍情况",response = TAppUserEquipment.class)
    @GetMapping(value = "/open/t-app-user/getDetailTeam")
    public R<TAppUserEquipment> getDetailTeam() {
        String userId = tokenService.getLoginUserApplet().getUserId();
        TAppUserEquipment tAppUserEquipment = appUserEquipmentService.getOne(Wrappers.lambdaQuery(TAppUserEquipment.class).eq(TAppUserEquipment::getAppUserId, userId));
        return R.ok(tAppUserEquipment);
    }
 
    /**
     * 查看人员管理详情--修改队伍情况
     */
    @ApiOperation(value = "查看人员管理详情--修改队伍情况",response = UpdateDetailTeamDto.class)
    @PostMapping(value = "/api/t-app-user/updateDetailTeam")
    public R<?> updateDetailTeam(@RequestBody String param) {
        String userId = tokenService.getLoginUserApplet().getUserId();
        UpdateDetailTeamDto dto = JSON.parseObject(param, UpdateDetailTeamDto.class);
        TAppUserEquipment tAppUserEquipment = appUserEquipmentService.getOne(Wrappers.lambdaQuery(TAppUserEquipment.class).eq(TAppUserEquipment::getAppUserId, userId));
        tAppUserEquipment.setPersonCount(dto.getPersonCount());
        tAppUserEquipment.setEquipmentCount(dto.getEquipmentCount());
        appUserEquipmentService.updateById(tAppUserEquipment);
        return R.ok();
    }
 
 
 
    /**
     * 用户打点
     */
    @ApiOperation(value = "用户打点",response = TAppUserLocation.class)
    @PostMapping(value = "/api/t-app-user/appUserLocation")
    public R<?> appUserLocation(@RequestBody String param) {
        TAppUserLocation location = JSON.parseObject(param,TAppUserLocation.class);
        String userId = tokenService.getLoginUserApplet().getUserId();
        location.setAppUserId(userId);
        appUserLocationService.save(location);
        return R.ok();
    }
 
    /**
     * 用户实时定位上传
     */
    @ApiOperation(value = "用户实时定位上传")
    @PostMapping(value = "/open/t-app-user/positioningUpload")
    public R<String> positioningUpload(@RequestParam(value = "lon") String lon ,
                                       @RequestParam(value = "lat") String lat ) {
        String userId = tokenService.getLoginUserApplet().getUserId();
        String location = redisCache.getCacheObject(Constants.LOCATION + userId + ":" + LocalDate.now());
        if(StringUtils.hasLength(location)){
            redisCache.setCacheObject(Constants.LOCATION + userId + ":" + LocalDate.now(), location + ";" +lon + "," + lat);
        }else {
            redisCache.setCacheObject(Constants.LOCATION + userId + ":" + LocalDate.now(), lon + "," + lat);
        }
        // 实时定位点
        redisCache.setCacheObject(Constants.LOCATION + userId, lon + "," + lat);
        return R.ok();
    }
 
    /**
     * 用户打点
     */
    @ApiOperation(value = "获取用户打点数据",response = TAppUserLocation.class)
    @GetMapping(value = "/open/t-app-user/getAppUserLocation")
    public R<List<TAppUserLocation>> getAppUserLocation() {
        String userId = tokenService.getLoginUserApplet().getUserId();
        List<TAppUserLocation> list = appUserLocationService.list(new LambdaQueryWrapper<TAppUserLocation>().eq(TAppUserLocation::getAppUserId, userId).orderByDesc(TAppUserLocation::getTime));
        return R.ok(list);
    }
 
    /**
     * 用户打点
     */
    @ApiOperation(value = "获取用户打点数据--详情",response = TAppUserLocation.class)
    @PostMapping(value = "/open/t-app-user/getAppUserLocationFromId")
    public R<TAppUserLocation> getAppUserLocationFromId(@RequestBody String param) {
        UserIdDto dto = JSON.parseObject(param, UserIdDto.class);
        TAppUserLocation location = appUserLocationService.getById(dto.getId());
        return R.ok(location);
    }
 
 
}