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);
|
}
|
}
|
}
|
|
}
|