yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
package com.qianwen.smartman.modules.system.service.impl;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.validation.constraints.NotEmpty;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.smartman.modules.system.entity.TopMenu;
import com.qianwen.smartman.modules.system.entity.TopMenuSetting;
import com.qianwen.smartman.modules.system.mapper.TopMenuMapper;
import com.qianwen.smartman.modules.system.service.ITopMenuService;
import com.qianwen.smartman.modules.system.service.ITopMenuSettingService;
 
@Service
public class TopMenuServiceImpl extends BaseServiceImpl<TopMenuMapper, TopMenu> implements ITopMenuService {
    private final ITopMenuSettingService topMenuSettingService;
 
 
    public TopMenuServiceImpl(final ITopMenuSettingService topMenuSettingService) {
        this.topMenuSettingService = topMenuSettingService;
    }
 
    @Override // org.springblade.modules.system.service.ITopMenuService
    @Transactional(rollbackFor = {Exception.class})
    public boolean grant(@NotEmpty List<Long> topMenuIds, @NotEmpty List<Long> menuIds) {
        this.topMenuSettingService.remove(Wrappers.<TopMenuSetting>update().lambda().in(TopMenuSetting::getTopMenuId, topMenuIds));
        /*
        this.topMenuSettingService.remove((Wrapper) Wrappers.update().lambda().in((v0) -> {
            return v0.getTopMenuId();
        }, topMenuIds));*/
        List<TopMenuSetting> menuSettings = new ArrayList<>();
        topMenuIds.forEach(topMenuId -> {
            menuIds.forEach(menuId -> {
                TopMenuSetting menuSetting = new TopMenuSetting();
                menuSetting.setTopMenuId(topMenuId);
                menuSetting.setMenuId(menuId);
                menuSettings.add(menuSetting);
            });
        });
        this.topMenuSettingService.saveBatch(menuSettings);
        return true;
    }
}