yyy
2026-05-17 e02bf5a481c0301baf40f9f729ee49f1037a0854
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
package com.xiaopeng.operation.controller;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.DesensitizedUtil;
import com.xiaopeng.api.feignClient.account.SysGroupMenuClient;
import com.xiaopeng.api.model.account.SysUser;
import com.xiaopeng.api.model.operation.XpTargetedService;
import com.xiaopeng.api.model.operation.XpWhitelist;
import com.xiaopeng.api.query.operation.XpTargetedServiceQuery;
import com.xiaopeng.api.vo.account.LoginUser;
import com.xiaopeng.api.vo.operation.XpTargetedServiceVehicleVo;
import com.xiaopeng.api.vo.operation.XpTargetedServiceVo;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.utils.bean.BeanUtils;
import com.xiaopeng.common.core.web.page.PageInfo;
import com.xiaopeng.common.log.annotation.AdminOperationLog;
import com.xiaopeng.common.log.enums.AdminBusinessType;
import com.xiaopeng.common.log.enums.AdminOperationType;
import com.xiaopeng.common.security.service.TokenService;
import com.xiaopeng.operation.dto.WhitelistAddDto;
import com.xiaopeng.operation.dto.WhitelistEditDto;
import com.xiaopeng.operation.query.WhitelistPageListQuery;
import com.xiaopeng.operation.service.XpTargetedServiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
@RestController
@RequestMapping("")
@Api(tags = "定向服务")
@Slf4j
public class XpTargetedServiceController {
 
    @Resource
    XpTargetedServiceService xpTargetedServiceService;
    @Resource
    private TokenService tokenService;
    @Resource
    private SysGroupMenuClient groupMenuClient;
 
 
    @ApiOperation(value = "定向服务分页", tags = {"管理后台-定向服务分页"})
    @PostMapping("/api/v1/targetedService/pageList")
    public R<PageInfo<XpTargetedServiceVo>> pageList(@RequestBody XpTargetedServiceQuery query) {
        PageInfo<XpTargetedServiceVo> pageList = xpTargetedServiceService.pageList(query);
        return R.ok(pageList);
    }
    @ApiOperation(value = "定向服务-详情", tags = {"管理后台-定向服务详情"})
    @GetMapping("/api/v1/targetedService/detail")
    public R<XpTargetedServiceVo> detail(@RequestParam Long id) {
        LoginUser loginUser = tokenService.getLoginUser();
        if (id == null) {
            return R.fail("ID不能为空");
        }
        XpTargetedServiceVo vo = xpTargetedServiceService.getById(id);
        if (vo == null) {
            return R.fail("数据不存在");
        }
        if(!loginUser.getPhoneDesensitizationExempt()){
            vo.getWhitelistList().forEach(s->s.setAccount(DesensitizedUtil.mobilePhone(s.getAccount())));
        }
 
        return R.ok(vo);
    }
 
 
    /**
     * 新增白名单
     */
    @PostMapping("/api/v1/targetedService/add")
    @ApiOperation(value = "定向服务-添加", tags = {"管理后台-定向服务添加"})
    @AdminOperationLog(
            businessType = AdminBusinessType.TARGETED_SERVICE,
            operationType = AdminOperationType.ADD,
            content = "新增定向服务",
            appendRequestData = true
    )
    public R add(@Validated @RequestBody XpTargetedServiceVo dto) {
        SysUser sysUser = tokenService.getLoginUser().getSysUser();
        xpTargetedServiceService.add(dto, sysUser);
 
        return R.ok();
    }
 
    /**
     * 编辑白名单
     */
    @PostMapping("/api/v1/targetedService/edit")
    @ApiOperation(value = "定向服务-修改", tags = {"管理后台-定向服务修改"})
    @AdminOperationLog(
            businessType = AdminBusinessType.TARGETED_SERVICE,
            operationType = AdminOperationType.EDIT,
            content = "编辑定向服务",
            appendRequestData = true
    )
    public R edit(@Validated @RequestBody XpTargetedServiceVo dto) {
        if(dto.getId() == null){
            return R.fail("ID不能为空");
        }
        XpTargetedService byId = xpTargetedServiceService.getById(dto.getId());
        if(byId == null){
            return R.fail("数据不存在");
        }
 
        SysUser sysUser = tokenService.getLoginUser().getSysUser();
        xpTargetedServiceService.edit(dto, sysUser);
        return R.ok();
    }
 
    /**
     * 修改状态
     */
    @PostMapping("/api/v1/targetedService/updateStatus")
    @ApiOperation(value = "定向服务-修改状态", tags = {"管理后台-定向服务修改状态"})
    @AdminOperationLog(
            businessType = AdminBusinessType.TARGETED_SERVICE,
            operationTypeExpression = "#p1 == 1 ? T(com.xiaopeng.common.log.enums.AdminOperationType).ENABLE : T(com.xiaopeng.common.log.enums.AdminOperationType).DISABLE",
            contentExpression = "(#p1 == 1 ? '启用定向服务,id=' : '禁用定向服务,id=') + #p0",
            appendRequestData = false
    )
    public R updateStatus(@RequestParam Long id, @RequestParam Integer status) {
        if (id == null) {
            return R.fail("ID不能为空");
        }
        if (status == null) {
            return R.fail("状态不能为空");
        }
        
        SysUser sysUser = tokenService.getLoginUser().getSysUser();
        boolean b = xpTargetedServiceService.updateStatus(id, status, sysUser);
        if(b){
            return R.ok();
        }
        return R.fail("修改失败");
    }
 
 
 
    /**
     * 批量删除
     */
    @PostMapping("/api/v1/targetedService/deleteByIds")
    @ApiOperation(value = "定向服务-批量删除", tags = {"管理后台-定向服务批量删除"})
    @AdminOperationLog(
            businessType = AdminBusinessType.TARGETED_SERVICE,
            operationType = AdminOperationType.DELETE,
            contentExpression = "'批量删除定向服务,ids=' + #p0.ids",
            appendRequestData = false
    )
    public R deleteByIds(@RequestBody XpTargetedServiceQuery query ) {
        if(CollUtil.isEmpty(query.getIds())){
            return R.fail("ID列表不能为空");
        }
        SysUser sysUser = tokenService.getLoginUser().getSysUser();
        return xpTargetedServiceService.deleteByIds(query.getIds(), sysUser);
    }
 
    /**
     * 根据用户ID和城市编码获取
     * @param appUserId  用户ID
     * @param cityCode   城市编码
     * @return
     */
    @GetMapping("/logan/inner/v1/targetedService/findListByUserIdAndCityCode")
    public R<List<XpTargetedServiceVehicleVo>> findListByUserIdAndCityCode(@RequestParam Long appUserId, @RequestParam String cityCode){
        return R.ok(xpTargetedServiceService.findListByUserIdAndCityCode(appUserId,cityCode));
    }
 
 
    /**
     * 获取定向服务权限
     * @param appUserId
     * @param cityCode
     * @return
     */
    @GetMapping("/logan/inner/v1/targetedService/getTargetedServiceWeight")
    public R<Integer> getTargetedServiceWeight(@RequestParam("appUserId") Long appUserId, @RequestParam("cityCode") String cityCode){
        Integer targetedServiceWeight = xpTargetedServiceService.getTargetedServiceWeight(appUserId, cityCode);
        return R.ok(targetedServiceWeight);
    }
 
}