whycxzp
2023-03-28 aaa2e601eb2a6806e761d4424fcaaf43a95fdcfd
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.dto.Response;
import com.whyc.mapper.MenuUserMapper;
import com.whyc.pojo.MenuUser;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class MenuUserService {
 
    @Resource
    private MenuUserMapper mapper;
 
    public List<MenuUser> getList(int userId) {
        QueryWrapper<MenuUser> query = Wrappers.query();
        query.eq("userId",userId);
        return mapper.selectList(query);
    }
 
    public void addList(int userId, List<MenuUser> menuList) {
        //校验是否存在,存在则剔除
        List<MenuUser> existsList = getList(userId);
        List<Integer> existsIdList = existsList.stream().map(menuUser -> menuUser.getId()).collect(Collectors.toList());
        for (MenuUser menuUser : menuList) {
            Integer id = menuUser.getId();
            if(existsIdList.contains(id)){
                menuList.remove(menuUser);
            }
        }
        mapper.insertBatchSomeColumn(menuList);
    }
 
    public void deleteList(List<Integer> numList) {
        mapper.deleteBatchIds(numList);
    }
}