cloudroam
3 天以前 3a819e4f668c15e8b77b188b322470da12bb7a43
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
package com.mzl.flower.service.system;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.system.CreateMenuDTO;
import com.mzl.flower.dto.request.system.UpdateMenuDTO;
import com.mzl.flower.dto.response.system.MenuDTO;
import com.mzl.flower.dto.response.system.MenuTreeDTO;
import com.mzl.flower.entity.system.PartnerMenu;
import com.mzl.flower.mapper.system.PartnerMenuMapper;
import com.mzl.flower.service.BaseService;
import com.mzl.flower.utils.TreeBuilderUtil;
import com.mzl.flower.utils.UUIDGenerator;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
@Service
@Transactional
public class PartnerMenuService extends BaseService {
    @Autowired
    private PartnerMenuMapper partnerMenuMapper;
 
    public PartnerMenu getMenu(String id) {
        return partnerMenuMapper.selectById(id);
    }
 
    public void addMenu(CreateMenuDTO dto) {
        PartnerMenu menu = new PartnerMenu();
        BeanUtils.copyProperties(dto, menu);
        menu.setId(UUIDGenerator.getUUID());
        menu.setIsVisible(Constants.Y);
        menu.setStatus(Constants.STATUS_ACTIVE);
 
        partnerMenuMapper.insert(menu);
    }
 
    public List<MenuTreeDTO> searchOperationMenu() {
        List<MenuTreeDTO> treeList = partnerMenuMapper.selectListOrderBySeq();
        for (MenuTreeDTO menuTreeDTO : treeList) {
            menuTreeDTO.setLabel(menuTreeDTO.getMenuName());
            menuTreeDTO.setPath(menuTreeDTO.getMenuHref());
            menuTreeDTO.setName(menuTreeDTO.getMenuName());
        }
        treeList = (List<MenuTreeDTO>) TreeBuilderUtil.buildListToTree(treeList);
        return treeList;
    }
 
    public MenuDTO getMenuDetail(String id) {
        PartnerMenu menu = getMenu(id);
 
        //返回对象
        MenuDTO menuDTO = new MenuDTO();
        if (menu != null) {
            BeanUtils.copyProperties(menu, menuDTO);
        }
        return menuDTO;
    }
 
    public void updateMenu(UpdateMenuDTO dto) {
        PartnerMenu menu = getMenu(dto.getId());
        BeanUtils.copyProperties(dto, menu);
        partnerMenuMapper.updateById(menu);
    }
 
    public void deleteMenu(String id) {
        PartnerMenu menu = getMenu(id);
        menu.setStatus(Constants.STATUS_DELETED);
        partnerMenuMapper.updateById(menu);
 
        List<PartnerMenu> menus = partnerMenuMapper.selectList(new QueryWrapper<PartnerMenu>().eq("PARENT_ID", id));
        if (menus != null && menus.size() > 0) {
            for (PartnerMenu children : menus) {
                deleteMenu(children.getId());
            }
        }
    }
}