huliguo
2025-04-23 f2070facdb5715e7349df69cfe257289c680d292
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.core.conditions.query.QueryWrapper;
import com.ruoyi.account.api.model.AppUserShop;
import com.ruoyi.account.mapper.AppUserMapper;
import com.ruoyi.account.mapper.AppUserShopMapper;
import com.ruoyi.account.service.AppUserService;
import com.ruoyi.account.service.AppUserShopService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
 
/**
 * @author zhibing.pu
 * @Date 2024/12/2 9:21
 */
@RestController
@RequestMapping("/appUserShop")
public class AppUserShopController {
    @Resource
    private AppUserShopService appUserShopService;
    @Resource
    private AppUserService appUserService;
    @Resource
    private AppUserShopMapper appUserShopMapper;
    @Resource
    private TokenService tokenService;
 
 
    @GetMapping("/getUserShopListByUserId")
    public R<List<AppUserShop>> getUserShopListByUserId(@RequestParam("userId") Long userId){
        return R.ok(appUserShopMapper.selectList(new LambdaQueryWrapper<AppUserShop>().eq(AppUserShop::getAppUserId, userId)));
    }
 
    @PostMapping("/addAppUserShop")
    public R<Void> add(@RequestBody AppUserShop appUserShop) {
        long count = appUserShopService.count(new LambdaQueryWrapper<AppUserShop>()
                .eq(AppUserShop::getAppUserId, appUserShop.getAppUserId()).eq(AppUserShop::getShopId, appUserShop.getShopId()));
        if(0 == count){
            appUserShopService.save(appUserShop);
        }
        return R.ok();
    }
 
 
    @GetMapping("/shop/{userId}")
    public R<List<AppUserShop>> getAppUserShop(@PathVariable("userId") Long userId) {
        return R.ok(appUserShopService.list(new LambdaQueryWrapper<AppUserShop>()
                .eq(AppUserShop::getAppUserId,userId)));
    }
 
 
    /**
     * 删除门店用户关系数据
     * @param appUserShop
     * @return
     */
    @PostMapping("/delAppUserShop")
    public R delAppUserShop(@RequestBody AppUserShop appUserShop){
        LambdaQueryWrapper<AppUserShop> wrapper = new LambdaQueryWrapper<>();
        if(null != appUserShop.getAppUserId()){
            wrapper.eq(AppUserShop::getAppUserId, appUserShop.getAppUserId());
        }
        if(null != appUserShop.getShopId()){
            wrapper.eq(AppUserShop::getShopId, appUserShop.getShopId());
        }
        if(null != appUserShop.getRoleType()){
            wrapper.eq(AppUserShop::getRoleType, appUserShop.getRoleType());
        }
        appUserShopService.remove(wrapper);
        return R.ok();
    }
 
 
    /**
     * 保存关系数据
     * @param appUserShop
     */
    @PostMapping("/saveAppUserShop")
    public void saveAppUserShop(@RequestBody AppUserShop appUserShop){
        appUserShopService.save(appUserShop);
    }
 
    /**
     * 校验登录用户是否为门店店长
     */
    @GetMapping("/checkUserIsShopManager")
    public R<Boolean> checkUserIsShopManager(){
        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
        List<AppUserShop> list = appUserShopService.list(new LambdaQueryWrapper<AppUserShop>()
                .eq(AppUserShop::getAppUserId, loginUserApplet.getUserid())
                .eq(AppUserShop::getRoleType, 1));
        return R.ok(!CollectionUtils.isEmpty(list));
    }
 
 
    @PostMapping("/insert")
    R insert(@RequestBody AppUserShop appUserShop){
        appUserShopService.save(appUserShop);
        return R.ok();
    }
    @DeleteMapping("/delete")
    R delete(@RequestParam("id") Integer id,@RequestParam("userId") Long userId){
        LambdaQueryWrapper<AppUserShop> wrapper = new LambdaQueryWrapper<AppUserShop>();
        wrapper.eq(AppUserShop::getShopId, id);
        wrapper.eq(AppUserShop::getAppUserId, userId);
        appUserShopService.remove(wrapper);
        return R.ok();
    }
 
}