Pu Zhibing
3 天以前 3244b550596e0330031b3f4547356927df83b0ad
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
package com.ruoyi.account.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.log.enums.OperatorType;
import com.ruoyi.common.security.annotation.Logical;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.other.api.dto.TagListQueryDto;
import com.ruoyi.account.api.model.TAppUserTag;
import com.ruoyi.account.service.TAppUserTagService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.api.domain.TUserTag;
import com.ruoyi.other.api.feignClient.OtherClient;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-08-06
 */
@RestController
@RequestMapping("/t-app-user-tag")
public class TAppUserTagController {
    @Resource
    private OtherClient otherClient;
    @Resource
    private TAppUserTagService appUserTagService;
    
    
    @RequiresPermissions(value = {"/coupon", "/userTag"}, logical = Logical.OR)
    @ApiOperation(value = "标签管理列表", tags = {"用户管理-用户标签管理"})
    @PostMapping(value = "/tags/page")
    public R<Page<TUserTag>> tagPage(@RequestBody TagListQueryDto tagListQueryDto) {
        //拿到单位列表
        R<Page<TUserTag>> pageR = otherClient.queryTagPage(tagListQueryDto);
        Page<TUserTag> data = pageR.getData();
        //拿到单位的用户数
        for (TUserTag record : data.getRecords()) {
            record.setCount(appUserTagService.lambdaQuery().eq(TAppUserTag::getUserTagId, record.getId()).count());
        }
        return R.ok(data);
    }
    
    
    @RequiresPermissions(value = {"/appUser/list"}, logical = Logical.OR)
    @ApiOperation(value = "标签管理列表", tags = {"用户管理-用户标签管理"})
    @GetMapping(value = "/tags/select")
    public R<List<TUserTag>> select() {
        TagListQueryDto tagListQueryDto = new TagListQueryDto();
        tagListQueryDto.setPageCurr(1);
        tagListQueryDto.setPageSize(999);
        R<Page<TUserTag>> pageR = otherClient.queryTagPage(tagListQueryDto);
        return R.ok(pageR.getData().getRecords());
    }
    
    
    @RequiresPermissions(value = {"/userTag/add", "/userTag/update"}, logical = Logical.OR)
    @ApiOperation(value = "标签添加或修改", tags = {"用户管理-用户标签管理"})
    @PostMapping(value = "/tags/add")
    @Log(title = "【用户标签管理】标签添加或修改", businessType = BusinessType.INSERT,operatorType = OperatorType.MANAGE)
    public R<Page<TUserTag>> tagAdd(@RequestBody TUserTag tUserTag) {
        //拿到单位列表
        otherClient.addorUpdateTag(tUserTag);
        return R.ok();
    }
    
    
    @RequiresPermissions(value = {"/userTag/del"}, logical = Logical.OR)
    @ApiOperation(value = "标签删除", tags = {"用户管理-用户标签管理"})
    @DeleteMapping(value = "/tags/delete")
    @Log(title = "【用户标签管理】删除标签", businessType = BusinessType.DELETE,operatorType = OperatorType.MANAGE)
    public R delete(String ids) {
        //拿到单位列表
        String[] split = ids.split(",");
 
         List<TAppUserTag> list = appUserTagService.lambdaQuery().in(TAppUserTag::getUserTagId,split).list();
         if (!list.isEmpty()){
             return R.fail("当前标签已有用户获取,无法删除");
         }
        for (String id : split) {
        otherClient.deleteTag(Integer.valueOf(id));
        }
        return R.ok();
    }
    
    
    /**
     * 获取用户标签关系
     * @param appUserTag
     * @return
     */
    @PostMapping(value = "/tags/getUserTag")
    public R<TAppUserTag> getUserTag(@RequestBody TAppUserTag appUserTag){
        TAppUserTag one = appUserTagService.getOne(new LambdaQueryWrapper<TAppUserTag>().eq(TAppUserTag::getAppUserId, appUserTag.getAppUserId())
                .eq(TAppUserTag::getUserTagId, appUserTag.getUserTagId()));
        return R.ok(one);
    }
    
    
    /**
     * 保存用户标签关系数据
     * @param appUserTag
     */
    @PostMapping(value = "/tags/addUserTag")
    public void addUserTag(@RequestBody TAppUserTag appUserTag){
        appUserTagService.save(appUserTag);
    }
}