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.AccountRole; import com.moral.mapper.AccountRoleMapper; import com.moral.service.AccountRoleService; import tk.mybatis.mapper.entity.Example; @Service public class AccountRoleServiceImpl implements AccountRoleService { private static Class ENTITY_CLASS = AccountRole.class; @Resource private AccountRoleMapper accountRoleMapper; @Override @Transactional public void addOrModify(AccountRole accountRole) { try { if (accountRole.getId() != null) { accountRoleMapper.updateByPrimaryKey(accountRole); } else { AccountRole accountRoleQuery = new AccountRole(); accountRoleQuery.setAccountId(accountRole.getAccountId()); accountRoleQuery.setRoleId(accountRole.getRoleId()); AccountRole accountRoleResult = accountRoleMapper.selectOne(accountRoleQuery); if (accountRoleResult == null) { accountRoleMapper.insertSelective(accountRole); } } } catch (Exception ex) { throw ex; } } @Override public int countByExample(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); return accountRoleMapper.selectCountByExample(example); } @Override public PageBean getAccountRoleList(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); if (pageBean.getPageSize() > 0) { PageHelper.startPage(pageBean.getPageIndex(), pageBean.getPageSize()); } List accountRoleList = accountRoleMapper.getAccountRoleList(example); return new PageBean(accountRoleList); } @Override @Transactional public void deleteByIds(Integer... ids) { if (ids != null && ids.length > 0) { if (ids.length == 1) { accountRoleMapper.deleteByPrimaryKeyOwn(ids[0]); } else { Example example = new Example(ENTITY_CLASS); example.or().andIn("id", Arrays.asList(ids)); accountRoleMapper.deleteByExample(example); } } } }