ZhuDongming
2019-10-18 a73c63037e6a5276ce6442873afc627e8cb2c9b0
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
package com.moral.service.impl;
 
import java.util.Arrays;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.github.pagehelper.PageHelper;
import com.moral.common.bean.PageBean;
import com.moral.common.util.ExampleUtil;
import com.moral.entity.RoleMenu;
import com.moral.mapper.RoleMenuMapper;
import com.moral.service.RoleMenuService;
 
import tk.mybatis.mapper.entity.Example;
 
@Service
public class RoleMenuServiceImpl implements RoleMenuService {
 
    private static Class ENTITY_CLASS = RoleMenu.class;
 
    @Resource
    private RoleMenuMapper roleMenuMapper;
 
    @Override
    @Transactional
    public void addOrModify(RoleMenu roleMenu) {
        try {
            if (roleMenu.getId() != null) {
                roleMenuMapper.updateByPrimaryKey(roleMenu);
            } else {
                RoleMenu roleMenuQuery = new RoleMenu();
                roleMenuQuery.setRoleId(roleMenu.getRoleId());
                roleMenuQuery.setMenuId(roleMenu.getMenuId());
                RoleMenu roleMenuResult = roleMenuMapper.selectOne(roleMenuQuery);
                if (roleMenuResult == null) {
                    roleMenuMapper.insertSelective(roleMenu);
                }
            }
        } catch (Exception ex) {
            throw ex;
        }
    }
 
    @Override
    public int countByExample(PageBean pageBean) {
        Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean);
        return roleMenuMapper.selectCountByExample(example);
    }
 
    @Override
    public PageBean getRoleMenuList(PageBean pageBean) {
        Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean);
        if (pageBean.getPageSize() > 0) {
            PageHelper.startPage(pageBean.getPageIndex(), pageBean.getPageSize());
        }
        List<RoleMenu> roleMenuList = roleMenuMapper.getRoleMenuList(example);
        return new PageBean(roleMenuList);
    }
 
    @Override
    @Transactional
    public void deleteByIds(Integer... ids) {
        if (ids != null && ids.length > 0) {
            if (ids.length == 1) {
                roleMenuMapper.deleteByPrimaryKeyOwn(ids[0]);
            } else {
                Example example = new Example(ENTITY_CLASS);
                example.or().andIn("id", Arrays.asList(ids));
                roleMenuMapper.deleteByExample(example);
            }
        }
    }
 
}