package com.nanometer.smartlab.service;
|
|
import com.nanometer.smartlab.dao.BaseRolePageDao;
|
import com.nanometer.smartlab.entity.BaseRolePage;
|
import com.nanometer.smartlab.exception.AlarmCode;
|
import com.nanometer.smartlab.exception.AlarmException;
|
import com.nanometer.smartlab.exception.BusinessException;
|
import com.nanometer.smartlab.exception.ExceptionEnumCode;
|
import com.nanometer.smartlab.util.IDUtils;
|
import com.nanometer.smartlab.util.MessageUtil;
|
import org.apache.commons.lang.StringUtils;
|
import org.apache.log4j.Logger;
|
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* Created by johnny on 17/11/20.
|
*/
|
@Service("baseRolePageService")
|
public class BaseRolePageServiceImpl implements BaseRolePageService {
|
|
private static Logger logger = Logger.getLogger(BaseRolePageService.class);
|
|
@Resource(name = "baseRolePageDao")
|
BaseRolePageDao baseRolePageDao;
|
|
@Transactional(propagation = Propagation.REQUIRED)
|
public List<BaseRolePage> getBaseRolePageList(Long roleId, Long pageId) {
|
try {
|
Map<String, Object> params = new HashMap<String, Object>();
|
if (roleId!=null) {
|
params.put("roleId", roleId);
|
}
|
if (pageId!=null) {
|
params.put("pageId", pageId);
|
}
|
return this.baseRolePageDao.getBaseRolePageList(params);
|
} catch (DataAccessException e) {
|
logger.error(e.getMessage(), e);
|
throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
|
}
|
}
|
|
@Transactional(propagation = Propagation.REQUIRED)
|
public BaseRolePage insertBaseRolePage(BaseRolePage baseRolePage) {
|
try {
|
// if (baseRolePage.getId() == null) {
|
// baseRolePage.setId(IDUtils.uuid());
|
// }
|
this.baseRolePageDao.insertBaseRolePage(baseRolePage);
|
return baseRolePage;
|
} catch (DuplicateKeyException ex) {
|
logger.warn(ex.getMessage(), ex);
|
throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode()));
|
} catch (DataIntegrityViolationException ex) {
|
logger.warn(ex.getMessage(), ex);
|
throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode()));
|
} catch (DataAccessException ex) {
|
logger.error(ex.getMessage(), ex);
|
throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex);
|
}
|
}
|
|
@Transactional(propagation = Propagation.REQUIRED)
|
public void batchInsertBaseRolePage(List<BaseRolePage> baseRolePages) {
|
try {
|
// if (baseRolePage.getId() == null) {
|
// baseRolePage.setId(IDUtils.uuid());
|
// }
|
this.baseRolePageDao.batchInsertBaseRolePage(baseRolePages);
|
} catch (DuplicateKeyException ex) {
|
logger.warn(ex.getMessage(), ex);
|
throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode()));
|
} catch (DataIntegrityViolationException ex) {
|
logger.warn(ex.getMessage(), ex);
|
throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode()));
|
} catch (DataAccessException ex) {
|
logger.error(ex.getMessage(), ex);
|
throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex);
|
}
|
}
|
|
@Transactional(propagation = Propagation.REQUIRED)
|
public boolean deleteBaseRolePage(Long roleId) {
|
try {
|
Map<String, Object> params = new HashMap<String, Object>();
|
params.put("roleId", roleId);
|
int row = this.baseRolePageDao.deleteBaseRolePage(params);
|
if (row == 0) {
|
return false;
|
}
|
return true;
|
} catch (DataIntegrityViolationException ex) {
|
logger.warn(ex.getMessage(), ex);
|
throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode()));
|
} catch (DataAccessException ex) {
|
logger.error(ex.getMessage(), ex);
|
throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex);
|
}
|
}
|
}
|