xuhy
2026-04-19 73242feacea752b9efb8f294d3f85da26bcfdb7d
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
package com.xiaopeng.operation.controller;
 
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.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.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;
 
 
    @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) {
        if (id == null) {
            return R.fail("ID不能为空");
        }
        XpTargetedServiceVo vo = xpTargetedServiceService.getById(id);
        if (vo == null) {
            return R.fail("数据不存在");
        }
        return R.ok(vo);
    }
 
 
    /**
     * 新增白名单
     */
    @PostMapping("/api/v1/targetedService/add")
    @ApiOperation(value = "定向服务-添加", tags = {"管理后台-定向服务添加"})
    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 = {"管理后台-定向服务修改"})
    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 = {"管理后台-定向服务修改状态"})
    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("修改失败");
    }
 
 
 
    /**
     * 批量删除
     */
    @GetMapping("/api/v1/whitelist/deleteByIds")
    @ApiOperation(value = "定向服务-批量删除", tags = {"管理后台-定向服务批量删除"})
    public R deleteByIds(String ids) {
        SysUser sysUser = tokenService.getLoginUser().getSysUser();
        List<Long> whiteIds = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList());
        return xpTargetedServiceService.deleteByIds(whiteIds, sysUser);
    }
 
}