package com.moral.service.impl; import java.util.Arrays; import java.util.Date; 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.Role; import com.moral.mapper.RoleMapper; import com.moral.service.RoleService; import com.moral.util.TkMybatisUtils; import tk.mybatis.mapper.entity.Example; @Service public class RoleServiceImpl implements RoleService { private static Class ENTITY_CLASS = Role.class; @Resource RoleMapper roleMapper; @Override @Transactional public void addOrModify(Role role) { try { role.setUpdateTime(new Date()); role.setUpdateUser(role.getUpdateUser()); if (role.getId() != null) { roleMapper.updateByPrimaryKey(role); } else { Role roleQuery = new Role(); roleQuery.setRoleCode(role.getRoleCode()); roleQuery.setIsDelete(Constants.IS_DELETE_FALSE); Role roleResult = roleMapper.selectOne(roleQuery); if (roleResult == null) { role.setIsDelete(Constants.IS_DELETE_FALSE); role.setCreateTime(new Date()); role.setCreateUser(role.getCreateUser()); roleMapper.insertSelective(role); } } } catch (Exception ex) { throw ex; } } @Override public int countByExample(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); TkMybatisUtils.addDeletesToExample(example); return roleMapper.selectCountByExample(example); } @Override public List getRoleListByName(String roleName) { List roleList = roleMapper.getRoleListByName(roleName); return roleList; } @Override public PageBean getRoleList(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); TkMybatisUtils.addDeletesToExample(example); if (pageBean.getPageSize() > 0) { PageHelper.startPage(pageBean.getPageIndex(), pageBean.getPageSize()); } List roleList = roleMapper.getRoleList(example); return new PageBean(roleList); } @Override @Transactional public void deleteByIds(Integer... ids) { Role role = new Role(); role.setIsDelete(Constants.IS_DELETE_TRUE); Example example = new Example(ENTITY_CLASS); example.or().andIn("id", Arrays.asList(ids)); roleMapper.updateByExampleSelective(role, example); } }