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
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
119
120
121
package com.moral.service.impl;
 
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
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.Constants;
import com.moral.common.bean.PageBean;
import com.moral.common.util.ExampleUtil;
import com.moral.entity.Menu;
import com.moral.mapper.MenuMapper;
import com.moral.service.MenuService;
import com.moral.util.TkMybatisUtils;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
 
import tk.mybatis.mapper.entity.Example;
 
@Service
public class MenuServiceImpl implements MenuService {
 
    private static Class ENTITY_CLASS = Menu.class;
 
    @Resource
    private MenuMapper menuMapper;
 
    @Override
    @Transactional
    public void addOrModify(Menu menu) {
        try {
            menu.setUpdateTime(new Date());
            menu.setUpdateUser(menu.getUpdateUser());
            if (menu.getId() != null) {
                menuMapper.updateByPrimaryKeySelective(menu);
            } else {
                Menu menuQuery = new Menu();
                menuQuery.setMenuCode(menu.getMenuCode());
                menuQuery.setIsDelete(Constants.IS_DELETE_FALSE);
                Menu menuResult = menuMapper.selectOne(menuQuery);
                if (menuResult != null) {
                    menu.setId(menuResult.getId());
                    menuMapper.updateByPrimaryKeySelective(menu);
                } else {
                    System.out.println("channelId:"+menu.getChannelId());
                    menu.setChannelId(menu.getChannelId());
                    menu.setIsDelete(Constants.IS_DELETE_FALSE);
                    menu.setCreateTime(new Date());
                    menu.setCreateUser(menu.getCreateUser());
                    menuMapper.insertSelective(menu);
                }
            }
        } catch (Exception ex) {
            throw ex;
        }
    }
 
    @Override
    public PageBean queryByAllPageBean(PageBean pageBean) {
        Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean);
        List<Example.Criteria> criteriaList = example.getOredCriteria();
        if (criteriaList != null && criteriaList.size() > 0) {
            for (Example.Criteria cri : criteriaList) {
                cri.andNotEqualTo("isDelete", Constants.IS_DELETE_TRUE);
            }
        } else {
            example.or().andNotEqualTo("isDelete", Constants.IS_DELETE_TRUE);
        }
        if (example.getOrderByClause() == null || example.getOrderByClause().isEmpty()) {
            example.setOrderByClause("menu_name asc");
        }
        List<Menu> menuList = menuMapper.selectWithMenuNameByExample(example);
        Iterator<Menu> iterator = menuList.iterator();
        return new PageBean(menuList);
    }
 
    @Override
    public int countByExample(PageBean pageBean) {
        Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean);
        TkMybatisUtils.addDeletesToExample(example);
        return menuMapper.countByExample(example);
    }
 
    @Override
    public PageBean getMenuList(PageBean pageBean) {
        Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean);
        TkMybatisUtils.addDeletesToExample(example);
        if (pageBean.getPageSize() > 0) {
            PageHelper.startPage(pageBean.getPageIndex(), pageBean.getPageSize());
        }
        List<Menu> menuList = menuMapper.getMenuList(example);
        return new PageBean(menuList);
    }
 
    @Override
    public List<Menu> getMenuParentList(String menuName) {
        List<Menu> menuParentList = menuMapper.getParentMenuList(menuName);
        return menuParentList;
    }
 
    @Override
    @Transactional
    public void deleteByIds(Integer[] ids) {
        Menu menu = new Menu();
        menu.setIsDelete(Constants.IS_DELETE_TRUE);
        Example example = new Example(ENTITY_CLASS);
        example.or().andIn("id", Arrays.asList(ids));
        menuMapper.updateByExampleSelective(menu, example);
    }
 
    @Override
    public List<Menu> getMenuListByName(String menuName) {
        List<Menu> menuList = menuMapper.getMenuListByName(menuName);
        return menuList;
    }
}